Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JDBC Result Set

Status
Not open for further replies.

fatcodeguy

Programmer
Feb 25, 2002
281
CA
I was wondering if there was an already defined method for returning the row count from a result set. They have getColumnCount in ResultSetMetaData, but no getRowCount.. any other functions there, or do I write my own (easy enought I know...)

Thanks for the help
 
not sure if there is, if you find one let me know I have just had to rely on a simple SQL Count statement to return an integer for this purpose.
 
I haven't heard of one. But as you said a rowcount would not be difficult to write. You would just need a method that accepts a recordset and returns an int. The method would just need a while loop to loop through the recordset and a counter (which it will return) to count. You will also have to move the recordset pointer back to the head of the recordset before returning your int, as the recordset will be passed by referrence.
 
You can find the number of rows in a result set using the scrollable result set features in JDBC 2.0. eg.

ResultSet result_set = ....
result_set.last();
int row_count = result_set.getRow();

This will move the index to the last entry in the result set and then return the index of the last row (which happens to be the total number of rows).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top