Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Databases
Expertise: Beginner
Feb 18, 2000

ResultSet Positioning

Question:
How can I access the next and previous rows in a ResultSet when I connect to a database through a JDBC driver?

Answer:
The JDBC 1.0 API only allows you to move forward through a ResultSet with the next() method. The next() will set the ResultSet to point to the next row and return true if that row exists. If there is no other row, then it returns false, allowing you to iterate over the results of a query with a while loop.

The JDBC 2.0 API added the ability to move backward through a ResultSet as well as forward. This feature is not necessarily supported by all drivers. Backward movement is performed with the previous() methods which does exactly the same thing as next(), except it fetches the previous row rather than the next. JDBC 2.0 also adds support for relative positioning with the relative(int rows) method, which will move the result cursor the indicated number of rows from the current position where a negative number means to move backward.

DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap