Java ResultSet Interface

Last Updated : 8 Apr 2026

The ResultSet interface is used to store and process the result returned from a database query. It helps in reading data row by row from the database.

In this chapter, you will learn about the ResultSet interface, its methods, and how to retrieve and navigate data from a database.

What is ResultSet Interface in Java?

The ResultSet object maintains a cursor that points to a row of a table. Initially, the cursor is placed before the first row.

By default, a ResultSet moves only in the forward direction and is not updatable. However, we can make it scrollable and updatable by using special parameters in the createStatement() method.

Importing / Using ResultSet Interface

To use the ResultSet interface, we need to import it from the java.sql package.

Here is the syntax to use ResultSet interface:

Or we can use:

Methods of ResultSet Interface

The following table lists the important methods of the ResultSet interface.

MethodDescription
public boolean next():Moves the cursor to the next row.
public boolean previous():Moves the cursor to the previous row.
public boolean first():Moves the cursor to the first row.
public boolean last():Moves the cursor to the last row.
public boolean absolute(int row):Moves the cursor to the specified row number.
public boolean relative(int row):Moves the cursor relative to the current position.
public int getInt(int columnIndex):Returns data of the given column index as integer.
public int getInt(String columnName):Returns data of the given column name as integer.
public String getString(int columnIndex):Returns data of the given column index as String.
public String getString(String columnName):Returns data of the given column name as String.

Fields of ResultSet Interface

The ResultSet interface provides constants such as TYPE_SCROLL_INSENSITIVE, TYPE_SCROLL_SENSITIVE, and CONCUR_UPDATABLE to control cursor movement and update behavior.

  • TYPE_SCROLL_INSENSITIVE: This allows the ResultSet to move forward and backward. The changes made in the database after creating the ResultSet are not reflected.
  • TYPE_SCROLL_SENSITIVE: This also allows forward and backward movement. The changes made in the database are reflected in the ResultSet.
  • CONCUR_UPDATABLE: This allows the ResultSet to be updated. You can modify the data directly using the ResultSet object.

Example of ResultSet Interface

The following example demonstrates how to retrieve data from the 3rd row using a scrollable ResultSet.

Output:

101 Rahul 30000

Explanation:

This example shows how to use ResultSet to fetch data from a specific row. The cursor is moved to the 3rd row using absolute(), and the data is displayed.