How do i get the number of rows in Resultset?

Hi,
Is there a way to make the size of string array according to the number of records
from the Resultset? The other problem is the values in saRow are all null.Why is it so? Thanks for helping me in advance
String sql = "SELECT Name FROM UserType" ; << Return "Admin" "User" "CIO"
ResultSet rs = db.ExecuteSQL(sql);
     while (rs.next()) {
     int i=0,rowCount;
     String[] saRow = new String[2]; << supposed to use rowCount
     saRow[i++] = rs.getString("Name");
     System.out.println(saRow);
//System.out.println
Database Query Success
null << saRow value
null
null
null
null
null

Essentially, you can't. A ResultSet is not a set of rows in memory: it is a cponnection to a back end database. Potentially, you start getting results out of the result set while the database is still searching for more.
I see this all the time on these forums: people doing work in java that is better done on the database. If you want to know the number of records in the database, ask the database: "select count(*) from UserType". Especially once you start needing to search big tables.
However, in this case, where you are just loading up the types: why bother? You know that there wioll only be a few of them. Load the results into an ArrayList. Go to the JavaDocs that you downloaded with the JDK, go to the "guides" section, and see the guide on the collections API.

Similar Messages

  • How can I get the number of rows in my sql result, without a loop?

    Hello,
    I've a problem, I would like to get the number of rows in my sql result without make a loop like :
    while (rs.next()){
    int number = rs.getRow();
    Is there any method to do this, on the first element?
    Thx, STeF

    If you want to count how many rows are in result set, I dont think you can, but you could always run a count statement for that sql
    say your sql is
    select field1, field2, field3
    from table1, table2
    where field4=field5 ......
    then you can count the rows this statement returns by
    select count(*) from
    (say your sql is
    select field1, field2, field3
    from table1, table2
    where field4=field5 ......)
    This way you will get the count for just that sql

  • Urgent******how can i get the number of rows enterd by the user in a table

    Hi Frndz..
    As per my requirement i need to do the validations for the multipple rows in a table that was enterd by the user,
                   T
              The prob is how can i get that number of rows that enterd by user,
           WDMessageManager msg = wdComponentAPI.getMessageManager();
         String col1= "";
         String col2= "";
         double col3= 0;
         double col4= 0;
         double amount= 0;
         int nodesize = wdContext.nodeTest().size();
         try
         for(int i=0; i<=2 ; i++)
                   col1 = wdContext.nodeTest().getTestElementAt(i).getCol1();
                 //msg.reportSuccess("col1 size is :"+col1);
                   col2 = wdContext.nodeTest().getTestElementAt(i).getCol2();
                   col3 = wdContext.nodeTest().getTestElementAt(i).getCol3();
                   col4 = wdContext.nodeTest().getTestElementAt(i).getCol4();
                    amount = wdContext.nodeTest().getTestElementAt(i).getAmount();
              if(col1 == "" )
                        msg.reportException("Plz fil the col1 for line:",true);
                   break;
              else
              if(col2 == "" )
                                  msg.reportException("Plz fil the col2 for line:",true);
                             break;
                        else
              if(col3 <= 0)
                   msg.reportException("Plz fil the col3:",true);
                   break;
              else
                   if(col4 <= 0)
                   msg.reportException("Plz fil the col4:",true);
                   break;
              msg.reportSuccess("skvgjhdfgasdfgsjkafguisafisenvtvyeriy");
                                                       wdThis.test();
         catch (Exception e)
                   msg.reportException("strMessage in catch block",true);
         this is the code am going
    Regards
    Rajesh

    Hi,
       You can try this:
    * Let's say the table's datasource is a node called Table  and it has two attributes first & second.
    * You want to check if any of these attributes has been changed by the user or not. If they have been
    * changed then you want to do some validations against them.
      int sizeOfTable = wdContext.nodeTable().size();
      for(int i = 0; i < sizeOfTable; i++){
         IPrivate<view name>.ITableElement ele = wdContext.nodeTable().getTableElementAt(i);
         if(ele.isChangedByClient(ITableElement.<attribute name>)){
            //value has been changed, do some validation. You can get the row index using ele.index().
    Regards,
    Satyajit.

  • How do I get the number of rows in a ResultSet?

    I checked the API, but didn't find a method that does this.

    You could try calling last() then getRow() to get the
    no of rows ...You probably need a scrollable resultset to do this, so that you can
    rewind back to the start and read the data in.
    I imagine you want to get a count, to size an array, before reading in the data ? Why not load it in an arraylist, then convert to an array afterwards ?
    regards,
    Owen

  • Get the number of rows affected by update statement

    Hi
    I'm working on an application that uses OCI as interface against an Oracle database.
    I'm trying to find out how i can get the number of rows affected by a query executed with OCIStmtExecute. it is not a select query.
    Best regards,
    Benny Tordrup

    If I run a bulk UPDATE query using OCIBindArrayOfStruct, is there a way I can tell which+ rows successfully updated?
    I have a file of records of which 75% of PKs are already in the table and will be updated, the other 25% aren't and should be inserted later. I want to attempt an UPDATE statement using OCIBindArrayOfStruct to execute in bulk and then check which entries in my bulk array successfully updated. If an array entry isn't successfully updated then I will assume it should be inserted and will store it for a Direct Path load later.
    Many thanks for any advice you can give as I've been trawling through the docs trying to find a solution for ages now.

  • How to get the number of rows in a repeating frame ?

    Hi all,
    When I launch a report from forms then sometimes there are data in the report and sometimes there are no data. And the problem is that when there are no data then the frame containing the repeating frame is still displaying and a blank page displays on the report.
    So I want to get the number of rows from the repeating frame so that I can code a format trigger on the frame to display or not the enclosing frame depending on the existence of data from the repeating frame.
    Thank you very much indeed.

    Dear Friend,
    You can achieve this. Define a summary column (say cnt). Select summary type as "COUNT". select any one of columns that are getting displayed in your repeating frame as summary column and provide "reset at" group name (or set this to report if you are defining this field at report level) . This "cnt" variable will contain how many records that will be fetched for your repeating frame (i.e. Group of Repeating frame). You can use this "CNT" variable in your format trigger.
    In this case there is no need to write before report trigger or anything.
    Regards,
    Manish Trivedi

  • How to get the number of rows in a DB-Cursor

    When i open a database cursor i do not know how much rows are stored in the cursor. To solve this problem i have to send a 'select count(1) ...' to get the number of rows before i set up the cursor. I think that this is not very clever and could possibly cause performance problems. But i need the num of rows to show the percentage of processed rows. Is there any other way to get the num of rows? May be by checking the cursor directly?
    Please help!
    Thanx a lot

    In order to find out how may rows are going to be processed, oracle has to visit every row. So with a cursor, there is no property that will accurately reflect the number of rows until you get to the last one. That said, you could use
    select count(*) over() as row_count, <rest of your columns> FROM <your table>
    which will give you the total row count agaist each row in the result set. There are performance penalties involved but they will be less than issuing the query twice, once to get the count and once to get the rows.
    Have a look on asktom for some very usefull info about all this.
    HTH

  • How to get the number of rows in a ResultSet

    Hello,
    I'm an intern and I'm trying to get the number of rows from result set in oracle using rs.last() and rs.beforeFirst() methods
    but I got an error. Could Below is my sample code:
    import java.sql.*;
    public class SarueckConnect {
    public static void main(String[] args) {
    Connection con = null;
    Statement stmt = null;
    ResultSet re = null;
    String[] ParamArray;
    ParamArray = new String[24];
    //Properties logon;
    try {
    Class.forName("oracle.jdbc.driver.OracleDriver"); //Loading the Oracle Driver.
    con = DriverManager.getConnection
    ("jdbc:oracle:thin:@258.8.159.215:1521:test_DB","data","data"); //making the connection DB.
    stmt = con.createStatement ();// Sending a query string to the database
    //stmt.executeUpdate("UPDATE test_table set steuk = 6 WHERE steuk = 5");
    ResultSet rs = stmt.executeQuery("SELECT mandt,kokrs,werks,arbpl,aufnr,vornr,ile01,"+
    "lsa01,ism01,ile02,lsa02,ism02,ile03,lsa03,ism03,ile04,lsa04,ism04,steuk,matnr,budat,"+
    "kostl,pernr,rueckid FROM test_table where steuk =6");
    //Print the result out.
    rs.last(); //This is the line which gives an error.
    int rows = rs.getRow();
    rs.beforeFirst();// I presume this is wrong to.
    ParamArray = new String[24*rows];
    int counter=0;
    while (rs.next()) {
    for (int i = 1; i <= 24; i++){
    ParamArray[i-1+(counter*24)] = rs.getString(i);
    System.out.print(rs.getString(i) + '\t');
    System.out.println();
    counter++;
    } catch(Exception e) {
    e.printStackTrace();
    } finally {
    try
    if(stmt != null) stmt.close();
    if(con != null) con.close();
    } catch (Exception exception) {
    exception.printStackTrace();
    TryBapi sap = new TryBapi(ParamArray);
    }When I run the code I do have the following ERROR Message:
    java.sql.SQLException: Invalid operation for forward only resultset : last
    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
    at oracle.jdbc.driver.BaseResultSet.last(BaseResultSet.java:91)
    at SarueckConnect.main(SarueckConnect.java:28)Please could any body Help me out here to figure out how to correct this?
    Any Help would be highly apprecited.

    make your result set scrollable...Not such a good idea. With Oracle, the JDBC driver will read and cache all the ResultSet in memory (with other DBMSs/drivers the behavior will probably be different, but you will still have some unnecessary overhead).
    You can do the caching yourself if you think it's worth it. If the piece of code you posted is why you need this for, then use a List or Vector and you won't need to know the size upfront.
    Alin,
    The jTDS Project.

  • How to get the number of rows written to the header of the spool file.

    Hi
    I need to create a header line for the spool file .
    the header line should include fixed length values .
    The header should include the number of records found in the table with a maximum begin date (begin_date is the column of the table)
    To get the header in the spool file , i wrote a select query has :-
    --SPOOL 'C:\Documents and Settings\abc\Desktop\output.TXT'
    select 'W'||to_char(sysdate,'MM/DD/YYYYMi:HH:SS')||lpad(max(rownum),9,'000000000') ||'R'||max(to_char(school_from_date,'MM/DD/YYYY')) ||
    rpad(' ',76,' ')
    from dad.school
    group by sysdate;
    SPOOL OFF
    which gets me all the rows in the table , but i only want the rows with the latest school_begin_date .
    how can i achieve that ...
    I know that a subquery should be written in the from clause to get the number of rows found with a maximum school_begin_date.
    select 'W'||to_char(sysdate,'MM/DD/YYYYMi:HH:SS')||lpad(max(rownum),9,'000000000') ||'R'||max(to_char(school_from_date,'MM/DD/YYYY')) ||
    rpad(' ',76,' ')
    from dad.school where
    select rownum from dad.school
    where school_begin_date = max(school_begin_date) ;
    the error i get is
    ORA-00934: group function is not allowed here
    I NEED HELP ..IN GETTING THE ROWNUM JUST FOR THE LATEST BEGIN_DATE ?
    PLS HELP ME IN WRITING THE QUERY .
    THANKS IN ADVANCE .

    Try this:
    select 'W'||to_char(sysdate,'MM/DD/YYYYMi:HH:SS')||lpad(max(rownum),9,'000000000')||'R'||max(to_char(school_from_date,'MM/DD/YYYY')) || rpad(' ',76,' ')
      from dad.school
    where school_begin_date = (select max(school_begin_date)
                                  from dad.school);

  • How to get the number of rows in a report region

    Hi all,
    Is there a way to get the number of rows returned in a report region, without issuing an additional "select count(*) from some_table"?
    I mean something like the substitution string #ROW_NUM# but for the total rows.
    Thanks,
    Pedro.

    http://download.oracle.com/docs/cd/E17556_01/doc/user.40/e15517/ui.htm#CHDDGGEG
    For classic report regions, the region footer supports the following substitution strings:#ROWS_FETCHED# shows the number of rows fetched by the Oracle Application Express reporting engine (the page size). You can use these substitution strings to display customized messages to the user. For example:
    Fetched #ROWS_FETCHED# rows in #TIMING# seconds.
    *#TOTAL_ROWS# displays the total number of rows that satisfy a SQL query used for a report.*
    #FIRST_ROW_FETCHED# and #LAST_ROW_FETCHED# display the range of rows displayed. For example:
    Row(s) #FIRST_ROW_FETCHED# through #LAST_ROW_FETCHED# of #ROWS_FETCHED# displayed>
    Ta,
    Trent

  • How can I limit the number of rows returned by a select stat

    How can I limit the number of rows returned by a select
    statement. I have a query where I return the number of stores
    that are located in a given area.. I only want to return the
    first twenty-five stores. In some instances there may be over
    200 stores in a given location.
    I know is SQL 7 that I can set the pagesize to be 25....
    Anything similiar in Oracle 8i?
    null

    Debbie (guest) wrote:
    : Chad Nale (guest) wrote:
    : : How can I limit the number of rows returned by a select
    : : statement. I have a query where I return the number of
    : stores
    : : that are located in a given area.. I only want to return the
    : : first twenty-five stores. In some instances there may be
    : over
    : : 200 stores in a given location.
    : : I know is SQL 7 that I can set the pagesize to be 25....
    : : Anything similiar in Oracle 8i?
    : If you are in Sql*Plus, you could add the statement
    : WHERE rownum <= 25
    : Used together with an appropriate ORDER BY you
    : could get the first 25 stores.
    Watch out. ROWNUM is run before ORDER BY so this would only
    order the 25 selected
    null

  • How do you set the number of rows in a spreadsheet, so that even when you drag data in, in writes over those rows instead of adding a new row?

    How do you set the number of rows you want in a spreadsheet, so that even when you drag data in, in writes over those rows instead of adding a new row?

    After the discovery reported above, I filed this report :
    Bug ID# 10073038
    Summary:
    When Numbers is used on a system with decimal comma a csv file may be good AND wrong
    Steps to Reproduce:
    With Numbers v2, you introduced an interesting enhancement.
    In system using the comma as decimal separator, Numbers requires csv files using the semi-colon as values delimiter.
    In fact it’s true if we OPEN the document dragging its icon on Numbers one or thru the open dialog.
    This said.
    (1) Drag and drop a csv built with the 'semi-colon' standard on a table or on a sheet
    (2) Drag and drop a csv built with the 'comma' standard on a table or on a sheet
    Expected Results:
    Every normally constituted user assume that in
    case (1) he will get a perfectly built table
    case (2) he will get every cells of a row in a single cell
    Actual Results:
    In fact you forgot the drag and drop way of use and in
    case (1) every values separated by semi-colon are inserted in a single cell
    case (2) values separated by comma are correctly spread in a table
    isn’t it ridiculous ?
    Regression:
    Except looking in  QuickView to see which is exactly the structure of the file to decide the way we will insert it in a Numbers document, we may use an applescript fair enough to replace the semi-colons by TAB characters
    or
    to replace the commas by TABs and the decimal periods by commas
    Notes:
    While I am on this subject, I wish to make two proposals:
    (1)  It would be fine to format the date according to the ISO format year-mm-dd when you export a Numbers doc to csv.
    Doing that, dates would be imported correctly in every countries.
    At this time, on an English system, you export as mm/dd/year.
    If the doc is open on a system using the format dd/mm/year, the results will be odd.
    On a system using the format dd/mm/year, you export this way and so, if the doc is open on a system using the format mm/dd/year the results are odd too.
    As every localized versions accept the ISO format (at least on entry), using it in the export scheme would give a correct behavior everywhere.
    (2) It would be fine to add the format Tab Separated Values in the Export pane.
    TSV + ISO date format would give documents opening flawlessly everywhere.
    Yvan KOENIG (VALLAURIS, France) dimanche 4 septembre 2011 21:27:41
    iMac 21”5, i7, 2.8 GHz, 4 Gbytes, 1 Tbytes, mac OS X 10.6.8 and 10.7.0
    My iDisk is : <http://public.me.com/koenigyvan>
    Please : Search for questions similar to your own before submitting them to the community

  • How do you limit the number of rows return from query?

    How do you limit the number of rows return from query? Do all databases support this kind of feature?

    i think the standard is limit
    to get the top 30
    select * from mytable LIMIT 30;returns the first 30 rows
    also if you want a range
    select * from mytable LIMIT 10,30;returns 30 rows starting from 10
    this last one is useful for displaying ranges... something similar happens in these forums when viewing topics and messages

  • How do I limit the number of rows retrieved at a time using RefCursor?

    I have a PL/SQL package in use, that returns a REF CURSOR. This is currently being used in a Forms 6i application. Now I want to develop an ASP.NET web application that displays exactly the same information as my Forms 6i module. In fact those two applications will be used concurrently for a while.
    I looked at the sample code provided on otn.oracle.com and decided to use the OracleDataAdapter.Fill()-method to fill a dataset and bind that dataset to a pageable GridView. Now I wonder, whether this method retrieves ALL records of the query at once and how I can limit the number of rows fetched? The Select statement retrieves up to 10000 rows at a time. Most of the time, a user is only interested in the first 20-30 rows. Forms 6i fetches more rows as the user scrolls down, how can I implement the same behavior in ODP.NET?
    - Markus

    Excuse me, but the reply does not quite answer my question. Maybe I did not explain my concerns clear enough:
    I understand the use of the two properties (RowSize and FetchSize) to reduce the amount of round trips needed to transfer the data - not the number of rows fetched in total. This would still lead to a situation where all rows are transferred, when I am using the OracleDataAdapter.Fill()-Method. Is this correct or did I misunderstand the function of this method?
    I quote the otherwise really helpful article you send me:
    Of course, there is a cost if the fetch size is arbitrarily large. More client-side memory and processor cycles will be needed to store and manage a larger amount of data. The goal is to find a high-performing balance between the number of round trips and the amount of data retrieved per trip.
    My RowSize is for sure a bit larger than the one in the given example. The query will probably be used by up to 100 users at a time, so I would like to limit the resource-costs not only on the network by the number of round trips, but also on the web-server which is storing all these records in it's memory per user-request.

  • How do you return the number of Rows in a ResultSet??

    How do you return the number of Rows in a ResultSet? It's easy enough to do in the SQL query using COUNT(*) but surely JDBC provides a method to return the number of rows.
    The ResultSetMetaData interface provides a method for counting the number of columns but nothing for the rows.
    Thanks

    No good way before JDBC2.0. u can use JDBC2.0 CachedRowSet.size() to retrieve the number of rows got by a ResultSet.

Maybe you are looking for

  • Lightning HDMI Adapter not working with iOS 6.1.2

    I have an iPhone 5 which was updated from 6.0.2 to 6.1.2 recently and the Lightning HDMI adapter stopped working altogether for video mirroring; was wondering if anyone has the same situation/any solution for this? I also have an iPad retina generati

  • Wierd window box all the way around my 16:9 footage

    Hey, Editing my feature using Final Cut Pro 5.1. When I export a sequence ot Quicktime I get this window like boarder all around. Why is this and how can I fix this? Footage is 16:9. Chris

  • Unused RAM filling up Mac Pro OS 10.9.2

    I have a 2009 Mac Pro running OS 10.9.2.  It has 8 processores and 24 GB of RAM.  Throughout the past couple of weeks, I have been seeing the unused RAM get filled up (I use a program to monitor my RAM usage and the white 'free' area starts to progre

  • Restrict users from input

    Hi Experts, Is there a way to restrict users from sending data through input schedules ? My requirement is to lock the weeks as we go . for example if data has already been sent in week1 no one should be able to modify it through input schedules. oth

  • Freezing video during playback HELP!

    I have a problem with video freezing for a split second on playback of DVD. I finished two projects (44 min and 32 min) on G4 dual processor, then moved over to new G5 with FCP Studio...upgrade. I finished editing and then went to export using compre