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

ResultSet

 
phani kon
Ranch Hand
Posts: 251
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the other alternative method for finding the number of records in the result set without using
while(rs.next)
{
;;
}
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think JDBC deliberately did not give us an API for that because it would force the resultset to retrieve all the rows for counting. The number could be high enough to be a serious performance drag. Under normal use the resulset retrieves some number of rows at a time as you move the cursor into them, but not all of at once.

A common suggestion is to run one query to select count and another to select the rows.

What do you want to do with the total number? Maybe we can figure out a way to live without it.
 
phani kon
Ranch Hand
Posts: 251
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply. But do you have any other method like scrollable result set..?
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are probably some SQL tricks ... select an extra computed column that is row number and sort descending so the first row has the row count. I'd still be more interested in making the requirement for row count go away.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic