Introduction
In Java, a ResultSet is an object that contains the results of executing a database query. It provides a way to access & manipulate the data returned from a database. The ResultSet interface in JDBC (Java Database Connectivity) allows you to move through its data & obtain the data from various columns.

In this article, we will learn about the commonly used methods of the ResultSet interface with an example of a scrollable ResultSet.
Commonly used methods of ResultSet interface:
The ResultSet interface provides several methods to access & manipulate the data returned from a database query. Let’s look at some of the commonly used methods:
1. next()
This method moves the cursor to the next row in the ResultSet object. It returns true if there is a next row & false if there are no more rows.
while (rs.next()) {
// process the current row
}
2. getXXX(int columnIndex) or getXXX(String columnLabel)
These methods retrieve the value of a column in the current row. The XXX represents the data type of the column, such as getInt(), getString(), getDate(), etc. You can specify either the column index (starting from 1) or the column label.
String name = rs.getString("name");
int age = rs.getInt("age");
3. beforeFirst()
This method moves the cursor to the position before the first row in the ResultSet object.
rs.beforeFirst();
4. afterLast()
This method moves the cursor to the position after the last row in the ResultSet object.
rs.afterLast();
5. first()
This method moves the cursor to the first row in the ResultSet object.
rs.first();
6. last()
This method moves the cursor to the last row in the ResultSet object.
rs.last();
7. absolute(int row)
This method moves the cursor to the specified row number in the ResultSet object. If the row number is positive, it counts from the beginning of the ResultSet. If the row number is negative, it counts from the end of the ResultSet.
rs.absolute(5); // moves to the 5th row
rs.absolute(-2); // moves to the second-to-last row
8. relative(int rows)
This method moves the cursor forward or backward by the specified number of rows relative to the current position.
rs.relative(3); // moves forward by 3 rows
rs.relative(-2); // moves backward by 2 rows
Note: These methods allow you to navigate through the ResultSet & access the data from different columns. It's important to note that the availability of some methods depends on the type of ResultSet & the JDBC driver being used.