aspose file tools*
The moose likes JDBC and the fly likes Counting number of rows in resultset Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Counting number of rows in resultset" Watch "Counting number of rows in resultset" New topic
Author

Counting number of rows in resultset

Glenny Dsilva
Ranch Hand

Joined: May 09, 2005
Posts: 42
Is there any way to count the number of rows in the result set.
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30938
    
158

Glenny,
The two most common alternatives are to do a separate query of:
"select count(*) from ... " or to count the rows as you loop through the data. The first is better if you just need to know how many rows there are. The second is better if you need to loop through the data anyway.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

A third possibility, if your Driver supports JDBC 3 is to use rs.afterLast() to move to the end and then rs.getRow() to get the row number. I always do it one of the ways listed by Jeanne.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Counting number of rows in resultset