aspose file tools*
The moose likes JDBC and the fly likes resultset question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "resultset question" Watch "resultset question" New topic
Author

resultset question

Tal Goldstein
Greenhorn

Joined: Apr 16, 2006
Posts: 14
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

Joined: May 24, 2003
Posts: 425
You have to use Scrollable resultset. Something like below



However check the JDBC Driver if it support Scrollable resultset.
stu derby
Ranch Hand

Joined: Dec 15, 2005
Posts: 333
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: resultset question