File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes How to get the size of a resultSet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "How to get the size of a resultSet" Watch "How to get the size of a resultSet" New topic
Author

How to get the size of a resultSet

aymane chetibi
Ranch Hand

Joined: Apr 12, 2006
Posts: 175
hi all,
I have a question.
After you execute a query, say from a servlet, and you get a resultSet. Is there any way you can know how many rows are there in this resultSet??
(I mean is there any function that does that?)
or do you just have to do it manually (while(rs.next()) i++; )?
Thank you
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18113
    
    8

There aren't any rows in the ResultSet until you ask the database to put them there. And yes, the normal way to ask the database for the row is to call "rs.next()". It's also possible to call "rs.last()" and go directly to the last row; this makes the database put all the rows into the ResultSet. However it's pointless to do that if you have a forward-only ResultSet as you will not be able to go back to the rows that you skipped.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to get the size of a resultSet
 
Similar Threads
Regarding reultset in stored procedures
how do you fetch a limited # of rows
desc command in java
Display table with decimal values like 0.2 problem
Calling Oracle Function that returns %ROWTYPE