Skip Headers

# Traversing Data With Scrollable Cursors

Previous

Next

Several methods let you navigate data with a scrollable cursor:

- `relative(int i)`: advances the row number in relation to the current row by one row

- `absolute(int i)`: places the cursor at an absolute row position, 1 being the first row

Several strategies are available for traversing data with cursors. For example, to start at the end of the data set and work toward the first record:

1. Call the `afterLast` method to place the cursor after the last row in the result set.

2. Use the `hasPrevious` method to determine whether there is a record above the current record. This method returns `false` when you reach the final record in the data set.

3. If the `hasPrevious` method returns `true`, call the `previous` method to move the cursor to the row prior to the current row and read that object.

These are common methods for data traversal, but they are not the only available methods. For more information about the available methods, see Oracle TopLink API Reference.

To use the `ScrollableCursor` object, the JDBC driver must be compatible with the JDBC 2.0 specifications.

Traversing with a Scrollable Cursor

    ReadAllQuery query = new ReadAllQuery(Employee.class);
    query.useScrollableCursor();
    ScrollableCursor cursor = (ScrollableCursor) session.executeQuery(query);

    while (cursor.hasNext()) {
        System.out.println(cursor.next().toString());
    }
    cursor.close();