ResultSet navigation

In this chapter you will learn:

  1. Navigating a Result Set

We can use the following methods in the ResultSet interface to move the cursor.

  • public void beforeFirst()
    Moves the cursor to just before the first row
  • public void afterLast()
    Moves the cursor to just after the last row
  • public boolean first()
    Moves the cursor to the first row
  • public void last()
    Moves the cursor to the last row.
  • public boolean absolute(int row)
    Moves the cursor to the specified row
  • public boolean relative(int row)
    Moves the cursor for given number of rows forward or backwards relative to its current position.
  • public boolean previous()
    Moves the cursor to the previous row. It returns false if the current row is the first row in the result set
  • public boolean next()
    Moves the cursor to the next row. It returns false if current row is the last row in the result set
  • public int getRow()
    Returns the row number that the cursor is pointing to.
  • public void moveToInsertRow()
    Moves the cursor to a special row in the result set that can be used to insert a new row into the database. The current cursor location is remembered.
  • public void moveToCurrentRow()
    Moves the cursor back to the current row if the cursor is currently at the insert row; otherwise, this method does nothing

Next chapter...

What you will learn in the next chapter:

  1. Move cursor in ResultSet forward and backword
Home » Java Tutorial » Statements, ResultSet, Exception, Warning

Statement

    Three types of statements
    Statement interface
    Insert
    Delete records
    Drop a table
    Batch operation

PreparedStatement

    PreparedStatement
    Insert
    Delete
    Update with parameters
    Batch operation
    ParameterMetaData
    Fetch size
    Set null vaue

CallableStatement

    CallableStatement

ResultSet

    ResultSet
    ResultSet Type
    ResultSet Concurrency
    Create a ResultSet
    ResultSet reading
    ResultSet get by column name
    ResultSet get column by index
    ResultSet next row
    ResultSet table row count
    ResultSet navigation
    ResultSet cursor forward and backward
    ResultSet first
    ResultSet last
    ResultSet after last
    ResultSet before first
    ResultSet absolute(2)
    ResultSet absolute(-1)
    ResultSet relative(-2)
    ResultSet relative(-2)
    ResultSet update
    Column Names
    Column count
    Column Characteristics

ResultSetMetaData

    Column Names
    Column count
    Column Characteristics

SQL Exception, SQL Warning

    SQL Exception
    SQLException information
    Chaining SQLExceptions
    Connection Warning
    PreparedStatement SQLWarning
    Statement SQLWarning
    ResultSet warning
    SQLWarning information