What are the methods provided by the ResultSet to navigate through it in JDBC?

JDBCJava 8MySQLMySQLi Database

We have two types of ResultSet objects namely, forward Only and, bi-directional as the names suggest you can move in only one direction (forward) in forward only ResultSet and, in bidirectional ResultSet you can move the pointer in both directions. The ResultSet interface provides several methods to navigate through both types of ResultSet objects.

Following table lists various methods to navigate through ResultSet object.

MethodDescription
next()This method moves the resultset pointer one row forward.
Previous() This method moves the resultset pointer one row backward.
first()This method moves the resultset pointer to the first row.
last()This method moves the resultset pointer to the last row.
relative()This method accepts an integer value representing the number of rows and, moves the resultset pointer forward or backward by given number of rows (positive integer forward, negative integer backward).
absolute()This method accepts an integer value representing the number of rows and, moves the resultset pointer to the given position in the resultset (starting from 1).
If you pass a positive integer to the resultset then the pointer is moved to the given position starting from first of the result set.
If you pass a negative integer to the resultset then the pointer is moved to the given position starting from last of the result set.
beforeFirst()This method moves the resultset pointer to its default position i.e. before first.
afterLast() This method positions the resultset pointer after the last row.
raja
Published on 20-Mar-2019 17:04:06
Advertisements