JDBC resultset


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: JDBC resultset

  1. #1
    prashant jani Guest

    JDBC resultset


    how can i find the no of rows returned in a resultset object.
    i want to limit the no of rows returned thru select stmt.
    database is oracle.i m using JSP.

  2. #2
    Paul Clapham Guest

    Re: JDBC resultset

    One way to find the number of rows returned is to read them all. Obviously
    this is not what you want to do. Another way to do this is to first create
    a summary resultset, using SQL that looks like "Select count(*) from <same
    table, same where clause, same group by clause>". This will return a single
    row with a single column that tells you how many rows will be in the detail
    resultset.

    There is no method like "rowCount()" because the JDBC driver may not know
    how many rows will be returned in the resultset when it gives it to you.
    For example, it may use a database index that matches your selection; in
    this case, it may just return the next record from the index when you do
    resultset.read().

    prashant jani <janiprashant@yahoo.com> wrote in message
    news:3993f3ff$1@news.devx.com...
    >
    > how can i find the no of rows returned in a resultset object.
    > i want to limit the no of rows returned thru select stmt.
    > database is oracle.i m using JSP.




  3. #3
    Marty Guest

    Re: JDBC resultset


    >> how can i find the no of rows returned in a resultset object.
    >> i want to limit the no of rows returned thru select stmt.
    >> database is oracle.i m using JSP.


    Here's another way, labourious but it gets a solid result:

    // assumes rs == a current resultset

    public int count()
    {
    if (rs == null) return 0;

    int currentRow = rs.getRow(); // save the row pos
    rs.last();
    int num = rs.getRow();
    if (currentRow == 0)
    rs.beforeFirst();
    else
    rs.absolute(currentRow);
    // go back to original row

    return num;
    }




  4. #4
    Sandip Guest

    Re: JDBC resultset


    For this to work, you will depend upon JDBC 2.0. if it it supported by the
    database you are using, then it's ok, otherwise you can't use this style
    to get the rowcount and your only alternative is to issue a count(*) command.

    "Marty" <marty@dot.net.au> wrote:
    >
    >>> how can i find the no of rows returned in a resultset object.
    >>> i want to limit the no of rows returned thru select stmt.
    >>> database is oracle.i m using JSP.

    >
    >Here's another way, labourious but it gets a solid result:
    >
    >// assumes rs == a current resultset
    >
    >public int count()
    >{
    > if (rs == null) return 0;
    >
    > int currentRow = rs.getRow(); // save the row pos
    > rs.last();
    > int num = rs.getRow();
    > if (currentRow == 0)
    > rs.beforeFirst();
    > else
    > rs.absolute(currentRow);
    > // go back to original row
    >
    > return num;
    >}
    >
    >
    >



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center