Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Counting number of rows in resultset

 
Glenny Dsilva
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there any way to count the number of rows in the result set.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34973
379
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic