• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how can I get Record Count from ResultSet?

 
Nailao liuage
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your help, I will change my Displayed Name.
 
fengzixuan zheng
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic