The moose likes JDBC and the fly likes Number of rows returned? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Number of rows returned?" Watch "Number of rows returned?" New topic

Number of rows returned?

Bloo Barton
Ranch Hand

Joined: May 09, 2005
Posts: 63
When I get my ResultSet how can I quickly check that rows have been returned so I am not trying to access data that is possibly not there?
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 41186
Calling rs.next() would return false right away if there were no rows returned.

Ping & DNS - my free Android networking tools app
Andy Grove

Joined: Nov 11, 2003
Posts: 18
If you want to know the number of rows before processing them, you could always issue a "SELECT COUNT(*) FROM TABLE WHERE ...." SQL statement first.
sunny sri

Joined: Jul 28, 2005
Posts: 3
if you want to know the no of rows in resultset without doing any work on that,then you just give the method last() on the resultset then it goes to last row of resultset.After that you can call the method getrows() it will give the return type int (row no)then you can easily find out the no rows.
see the method currectly(getrows())in API.

It is sorta covered in the JavaRanch Style Guide.
subject: Number of rows returned?
Similar Threads
How to find the number of rows in the resultset
efficient way to update data
Adding the rows in a JSP
How can i count the returned rows from a daabase ?
counting rows after joins varies