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

resultset question

 
Tal Goldstein
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all
is there a way to set the current position of the cursor in a resultset
to the row number that i choose.
for example if i have a resultset containing 1000 records and i want only the last 500,
is there a way i can set the cursor to start from record 500?

of course i can call next() method 500 times, but is there a more elegant way?
 
Purushoth Thambu
Ranch Hand
Posts: 425
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have to use Scrollable resultset. Something like below



However check the JDBC Driver if it support Scrollable resultset.
 
stu derby
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Purushothaman Thambu:
You have to use Scrollable resultset. Something like below



However check the JDBC Driver if it support Scrollable resultset.


Also however, many drivers (but not all) will still transfer those first 500 rows from the database to your driver, where the driver will iterate through them to the row you want. Same thing as what you're trying to avoid, just pushed down a level.

What you really want to do is write your SQL to avoid those first 500 rows totally. Here's SQL I would use on an Oracle DB to get the 2nd 100 rows from something:



"rownum" is an Oracle-supplied pseudo-column.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic