File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Number of rows in a ResultSet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Number of rows in a ResultSet" Watch "Number of rows in a ResultSet" New topic

Number of rows in a ResultSet

Warren Bell
Ranch Hand

Joined: Dec 20, 2000
Posts: 56
How do you find out how many rows there are in a ResultSet without running through every row and counting them?

Warren Bell
SJ Adnams
Ranch Hand

Joined: Sep 28, 2001
Posts: 925
what I've done in the past is to alias the rownum & order it desc in a subquery. that way you get the total number of rows of the query in the very first row.
I'm sure there are better ways - I guess it depends if you prefer to load the rdbms or the application.
I agree. Here's the link:
subject: Number of rows in a ResultSet
It's not a secret anymore!