Understanding ResultSet Interface

The ResultSet interface in JDBC is used to store and retrieve the data returned by a SQL query. It represents the rows and columns of the result produced by a SELECT statement. A ResultSet maintains a cursor that points to the current row, and methods such as next(), previous(), first(), and last() are used to move the cursor between rows. Data can be retrieved from columns using methods such as getInt(), getString(), getDouble(), and getDate(). It also provides methods to check for NULL values, determine the current row, and close the result set after use.

Methods of ResultSet:

Method Signature and Short Description

public boolean next()

Moves the cursor to the next row of the result set.

public boolean previous()

Moves the cursor to the previous row of the result set.

public boolean first()

Moves the cursor to the first row of the result set.

public boolean last()

Moves the cursor to the last row of the result set.

public boolean absolute(int row)

Moves the cursor to the specified row number.

public boolean relative(int rows)

Moves the cursor a specified number of rows forward or backward.

public int getInt(int columnIndex)

Retrieves the value of the specified column as an integer.

public String getString(int columnIndex)

Retrieves the value of the specified column as a String.

public double getDouble(int columnIndex)

Retrieves the value of the specified column as a double.

public float getFloat(int columnIndex)

Retrieves the value of the specified column as a float.

public boolean getBoolean(int columnIndex)

Retrieves the value of the specified column as a boolean.

public Date getDate(int columnIndex)

Retrieves the value of the specified column as a SQL date.

public String getString(String columnLabel)

Retrieves the value of the specified column using its column name.

public int getInt(String columnLabel)

Retrieves the value of the specified column as an integer using its column name.

public boolean wasNull()

Checks whether the last retrieved column value was SQL NULL.

public void close()

Releases the resources associated with the ResultSet.

public boolean isClosed()

Checks whether the ResultSet has been closed.

public int getRow()

Returns the current row number of the cursor.

Scroll to Top