Cursor movement

The iSeries™ Java™ Database Connectivity (JDBC) drivers support scrollable ResultSets. With a scrollable ResultSet, you can process rows of data in any order using a number of cursor-positioning methods.

The ResultSet.next method is used to move through a ResultSet one row at a time. With Java Database Connectivity (JDBC) 2.0, the iSeries JDBC drivers support scrollable ResultSets. Scrollable ResultSets allow processing the rows of data in any order by using the previous, absolute, relative, first, and last methods.

By default, JDBC ResultSets are always forward only, meaning that the only valid cursor-positioning method to call is next(). You have to explicitly request a scrollable ResultSet. See ResultSet types for more information.

With a scrollable ResultSet, you can use the following cursor-positioning methods:

Method Description
Next This method moves the cursor forward one row in the ResultSet.

The method returns true if the cursor is positioned on a valid row and false otherwise.

Previous The method moves the cursor backward one row in the ResultSet.

The method returns true if the cursor is positioned on a valid row and false otherwise.

First The method moves the cursor to the first row in the ResultSet.

The method returns true if the cursor is positioned on the first row and false if the ResultSet is empty.

Last The method moves the cursor to the last row in the ResultSet.

The method returns true if the cursor is positioned on the last row and false if the ResultSet is empty.

BeforeFirst The method moves the cursor immediately before the first row in the ResultSet.

For an empty ResultSet, this method has no effect. There is no return value from this method.

AfterLast The method moves the cursor immediately after the last row in the ResultSet.

For an empty ResultSet, this method has no effect. There is no return value from this method.

Relative (int rows) The method moves the cursor relative to its current position.
  • If rows is 0, this method has no effect.
  • If rows is positive, the cursor is moved forward that many rows. If there are fewer rows between the current position and the end of the ResultSet than specified by the input parameters, this method operates like afterLast.
  • If rows is negative, the cursor is moved backward that many rows. If there are fewer rows between the current position and the end of the ResultSet than specified by the input parameter, this method operates like beforeFirst.

The method returns true if the cursor in positioned on a valid row and false otherwise.

Absolute (int row) The method moves the cursor to the row specified by row value.

If row value is positive, the cursor is positioned that many rows from the beginning of the ResultSet. The first row is numbered 1, the second is 2, and so on. If there are fewer rows in the ResultSet than specified by the row value, this method operates the same way as afterLast.

If row value is negative, the cursor is positioned that many rows from the end of the ResultSet. The last row is numbered -1, the second to last is -2, and so on. If there are fewer rows in the ResultSet than specified by the row value, this method operates the same way beforeFirst.

If row value is 0, this method operates the same way as beforeFirst.

The method returns true if the cursor is positioned on a valid row and false otherwise.

Related concepts
ResultSet characteristics
Retrieve ResultSet data
Create ResultSets
Related tasks
Change ResultSets
Related reference
Example: ResultSet interface for IBM Developer Kit for Java