Java Reference
In-Depth Information
Updating a Result Set
The ResultSet interface contains a collection of update methods for updating
the data of a result set. As with the get methods, there are two update methods
for each data type: one that uses the column name and one that uses the col-
umn index.
For example, to update a String column of the current row of a result set,
you would use one of the following updateString() methods:
public void updateString(int columnIndex, String s) throws SQLException.
Changes the String in the specified column to the value of s.
public void updateString(String columnName, String s) throws SQLEx-
ception. Similar to the previous method, except that the column is
specified by its name instead of its index.
There are update methods for the eight primitive data types, as well as
String, Object, URL, and the SQL data types in the java.sql package.
Updating a row in the result set changes the columns of the current row in
the ResultSet object, but not in the underlying database. To update your
changes to the row in the database, you need to invoke the following method:
public void updateRow(). Updates the current row by updating the cor-
responding row in the database.
In the next section, Prepared Statements , I will demonstrate how to use the
update methods to update the data in the database.
The updateRow() method updates any changes to the current row in the
result set to the underlying database. Here are some other methods in the
ResultInterface that deal with the current result set row and the
corresponding database row:
public void deleteRow().
Deletes the current row from the
database.
public void refreshRow(). Refreshes the data in the result set to
reflect any recent changes in the database.
public void cancelRowUpdates().
Cancels any updates made on
the current row.
public void insertRow(). Inserts a row into the database. This
method can only be invoked when the cursor is pointing to the
insert row.
Search WWH ::




Custom Search