Ad Code

Ubdatable & Scrollable ResultSet Object + Java Details

ResultSet Object
In the Resultset a SQL statement executed, which reads data from the table and then return the resultset data. In order to accomplish resultset in a correct format it's necessary that query must be fine which then returns selected rows to be viewable in resultset.

java.sql.ResultSet  is the java command which returns the resultset from database query.

A ResultSet object maintains a cursor that shows the current row in the result set. Result set is just a term it means there are rows and columns representing your Database Table Columns and rows.

Updateable and Scrollable Resultset

  • With the help of such ResultSet, it is possible to move forward as well as backward with in ResultSet object.
  • Another advantage is, rows can be inserted, updated or deleted by using updatable ResultSet object.

Types of ResultSet

ResultSet.TYPE_FORWARD_ONLY: Cursor will only move forward throughout search result.

ResultSet.TYPE_SCROLL_INSENSITIVE: In this type of resultset cursor will move in both direction forward and backward, and the result set is not sensitive to changes made by others to the database that occur after the result set was created.
 
ResultSet.TYPE_SCROLL_SENSITIVE: Cursor will move in both direction forward and backward but is sensitive change can occur after result set occurs and user can change anything in the resultset.

Navigating a Result Set

public void beforeFirst() throws SQLException
Moves the cursor just before the first row.

-----------------
public void afterLast() throws SQLException
Moves the cursor just after the last row.

-----------------
public boolean first() throws SQLException
Moves the cursor to the first row.

-----------------
public void last() throws SQLException
Moves the cursor to the last row.

-----------------
public boolean absolute(int row) throws SQLException
Moves the cursor to the specified row.

-----------------
public boolean relative(int row) throws SQLException
Moves the cursor the given number of rows forward or backward, from where it is currently pointing.

-----------------
public boolean previous() throws SQLException
Moves the cursor to the previous row. This method returns false if the previous row is off the result set.

-----------------
public boolean next() throws SQLException
Moves the cursor to the next row. This method returns false if there are no more rows in the result set.

-----------------
public int getRow() throws SQLException
Returns the row number that the cursor is pointing to.

-----------------
public void moveToInsertRow() throws SQLException
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() throws SQLException
Moves the cursor back to the current row if the cursor is currently at the insert row; otherwise, this method does nothing
Reactions

Post a Comment

0 Comments