This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JDBC and the fly likes Size of ResultSet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Size of ResultSet" Watch "Size of ResultSet" New topic

Size of ResultSet

Butch C

Joined: Oct 18, 2000
Posts: 7
After executing a Statement which returns a ResultSet, is
there any method to call or a way to determine how many
rows are contained in the ResultSet without looping through
the ResultSet?

I would like to know how many rows are returned prior to processing
the ResultSet.
Anil Vupputuri
Ranch Hand

Joined: Oct 31, 2000
Posts: 527
JDBC1.2 API doesnt have this functionality ,where from JDBC2.0 it provides all userfriendly methods which u can access size of the resultset.For JDBC2.0API ,JDBC-ODBC bridge wont support so go for pure Java drivers i.e., thin drivers for Oracle.

SCJP 1.5, SCEA, ICED (287,484,486)
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Since the ResultSet doesn't actually contain all the rows (imagine doing a select * on a table with 100 million rows) but goes back to the database to get more rows as needed, I don't believe that the ResultSet has any way of knowing the actual size of the ResultSet.
Anil, is there a particular method you had in mind?

Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Deepika Wadhwa
Ranch Hand

Joined: Aug 05, 2000
Posts: 57
there is no way to get total row count from resultset.
but what u can do to get total no of rows returned, run a sql query before it to get count of your query.
i hope this will solve ur pb.

I agree. Here's the link:
subject: Size of ResultSet
Similar Threads
How to find the number of rows in the resultset
Number of rows in a ResultSet
OutOfMemoryError caused by PreparedStatements held in Connection
How to find no of Rows in my ResultSet