Result Set Navigation Methods
The following methods of the ResultSet interface can be used to navigate a result set. By default, the cursor can only be moved in the forward direction by calling the next() method. The other navigation methods (previous(), next(), first(), last(), absolute(), and relative(int row)) can only be used if scrolling is first enabled by setting the appropriate ResultSet type (Table 24.3, p. 1539).
boolean next()
Returns true if it is possible to move the cursor forward by one row from its current position; otherwise, it returns false. The return value false implies that either the cursor is after the last row or the result set is empty. Calling the next() method after it returns false will throw a SQLException.
boolean previous()
Returns true if it is possible to move the cursor to the previous row from its current position; otherwise, it returns false. The return value false implies that either the cursor is before the first row or the result set is empty. In both case, the cursor does not point to a valid row—in which case, calling a method on the ResultSet that requires a valid row will throw a SQLException.
boolean first()
Returns true if it is possible to move the cursor to the first row; otherwise, it returns false. The return value false implies that the result set is empty.
boolean last()
Returns true if it is possible to move the cursor to the last row; otherwise, it returns false. The return value false implies that the result set is empty.
boolean absolute(int rowNumber)
If the specified row number is positive, the cursor is moved to the absolute row number with respect to the beginning of the result set. Calling absolute(1) is the same as calling first().
If the given row number is negative, the cursor is moved to the absolute row number with respect to the end of the result set. Calling absolute(-1) is the same as calling last().
If the row number is zero, the cursor is moved to before the first row.
An attempt to position the cursor beyond the first or the last row in the result set leaves the cursor before the first row or after the last row, respectively.
boolean relative(int rows)
A positive/negative value in rows moves the cursor that many rows forward/ backward from the current position, respectively. Attempting to move beyond the first or the last row in the result set will set the cursor before the first row or after the last row, respectively.
Calling the method relative(1) is the same as calling the method next().
Calling the method relative(-1) is the same as calling the method previous().
Calling relative(0) is valid, but does not change the cursor position.