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

How do you know number of rows fetched by ResultSet?.

 
narender kaasam
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do you know number of rows fetched by ResultSet?.
 
Masoud Kalali
Author
Ranch Hand
Posts: 531
Java Mac OS X Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
there are several ways ,
one is to use setFetchsize(), by this way you set the fetch size explicity

The other one is to execute a select count(...) statement after or before your orijinal statement execution .

another way is to count the rows one by one

and the last way that i know is
 
stu derby
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Masoud Kalali:
there are several ways ,
one is to use setFetchsize(), by this way you set the fetch size explicity

[/CODE]


setFetchSize does NOT affect the number of rows in the ResultSet; it affects the number of rows that are buffered by the driver. It's a performance optimization setting, not a logical operation. Some drivers default their fetch size to "all rows" and will run the JVM out of memory with a very large ResultSet, some drivers have a default fetch size of 1 and therefore spend too much time waiting on network transfers of data, some drivers have a default fetch size that is larger but may not be optimal for any particular situation (the Oracle driver has default fetch size of 10 and people usually get better performance with a higher value for the fetch size).
 
Masoud Kalali
Author
Ranch Hand
Posts: 531
Java Mac OS X Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by narender kaasam:
How do you know number of rows fetched by ResultSet?.



maybe i did not understand the question.
 
stu derby
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Masoud Kalali:



maybe i did not understand the question.


More likely, you understood the question and meant to say "setMaxRows()" instead of "setFetchSize()".

setMaxRows() does what the name implies, limits the size of the returned ResultSet, so you know that your ResultSet is that size or smaller...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic