• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

No size method in ResultSet

 
Manohar Reddy Gopireddy
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no size method defined in ResultSet class. Is there any specific reason for this?
 
Scott Selikoff
author
Saloon Keeper
Posts: 4031
18
Eclipse IDE Flex Google Web Toolkit
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are going to read all of the results, then just call rs.next() and use a counter to keep track of the number that will be returned. In this manner, retrieving the count has no overhead.

If you are not going to read all of the results, then its wasteful to process data that you don't need. The optimal thing to do would be to reformulate the query to return count(*) of the records involved. Retrieving the count is an extra database call but in most cases it is better than executing a query to retrieve data you don't need.
 
Manohar Reddy Gopireddy
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Man...I am not expecting this silly answer from coderanchers. I know this can be in the way what you have explained. But i am asking why they have not provided the size method on the resultset object.

Thanks anyhow
 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Manohar Reddy Gopireddy wrote:Hey Man...I am not expecting this silly answer from coderanchers. I know this can be in the way what you have explained. But i am asking why they have not provided the size method on the resultset object.

Thanks anyhow

Because such method would be very inefficient and its usage would nearly always mean unnecessary wasting of significant amount of resources. Such method, even if it existed, should never be used, so this is the reason it does not exist in the first place.

It follows quite naturally from what Scott have answered you. That does not seem silly at all to me.
 
Paul Clapham
Sheriff
Posts: 21551
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And besides that, a result set doesn't actually have a "size" until you have materialized all of the records in it. If you haven't materialized all of the records then it's possible that some other process might modify the data which you selected but haven't read yet. Including adding records which would become part of your result set. In other words, "size" is a meaningless concept when applied to result sets.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic