wood burning stoves*
The moose likes JDBC and the fly likes how can I get Record Count from ResultSet? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "how can I get Record Count from ResultSet?" Watch "how can I get Record Count from ResultSet?" New topic
Author

how can I get Record Count from ResultSet?

Nailao liuage
Greenhorn

Joined: May 28, 2002
Posts: 4
Hi all:
When I execute query SQL statement and get a ResultSet. how can I get Record Count about this ResultSet?
Thanks a lot!
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

This is a fairly common question and I recommend using the search facility first. You'll get several threads like this one
Keep in mind that there are several options, and all the options are not always covered in each individual thread.
You can do a dummy call that returns a count of the results rather than the results,
You can iterate through the results as you process them and keep a count,
If you have scrollable ResultSets you can jump to the last and see what item number it is.
There may be others, but I forget...
Dave
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

"liuage",
The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at http://www.javaranch.com/name.jsp.
We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please edit your profile and select a new name which meets the requirements.
Thanks.
Dave
Nailao liuage
Greenhorn

Joined: May 28, 2002
Posts: 4
Thank you for your help, I will change my Displayed Name.
fengzixuan zheng
Ranch Hand

Joined: Aug 02, 2001
Posts: 31
Originally posted by liuage:
Hi all:
When I execute query SQL statement and get a ResultSet. how can I get Record Count about this ResultSet?
Thanks a lot!

I think you can do like this simplly:
ResultSet rs= ... ;
rs.getMetaData().getColumnCount();
[ June 03, 2002: Message edited by: fengzixuan zheng ]
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

Originally posted by fengzixuan zheng:

I think you can do like this simplly:
ResultSet rs= ... ;
rs.getMetaData().getColumnCount();
[ June 03, 2002: Message edited by: fengzixuan zheng ]

I wish it was that easy! but unfortunately it returns the number of columns in the resultset, not the number of rows.
Jamie
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how can I get Record Count from ResultSet?
 
Similar Threads
Display error when record not found
java.sql.SQLException: Exhausted Resultset
Count the Records
how can I get the record number of resultset?
ResultSet Manipulation