Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ResulSet Count

 
Ameya Thakur
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi EveryOne,
i wanna get the total no of records return by the resultset
which method should i use
i am not using JDBC 2.0 API.
Thanks in Advance
Kurt
 
Tony Alicea
Desperado
Sheriff
Posts: 3226
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mr. Cobain:
Welcome to JavaRanch!
Glad to hear the reports of your death were greatly exaggerated. Still, I'm going to have to ask you to have a look at the JavaRanch naming policy, which prohibits obviously fictitious names. Unless you can explain the technology that's allowing you to post from the afterlife, I must insist that you head over here and change your display name, pronto! Thanks, pardner.
 
Joe Ess
Bartender
Posts: 9340
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From the JDBC FAQ

18. There is a method getColumnCount in the JDBC API. Is there a similar method to find the number of rows in a result set?
No, but it is easy to find the number of rows. If you are using a scrollable result set, rs, you can call the methods rs.last and then rs.getRow to find out how many rows rs has. If the result is not scrollable, you can either count the rows by iterating through the result set or get the number of rows by submitting a query with a COUNT column in the SELECT clause.

I believe scrollable result sets were introduced in JDBC 2.0, so I think you are stuck with one of the two latter solutions.
[ February 12, 2004: Message edited by: Joe Ess ]
 
Jamie Robertson
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
be careful if you do use scrollable resultsets and use rs.last() method. It will iterate through the resultset until the last row, which will hold every record in memory. If you have a large resultset, this could eat up your memory quickly! I'd go with the count(*) query as Joe suggested
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic