Updating data in the ResultSet table using a PreparedStatement object.

Now you can set the cursor to a row
using one of the
positioning methods in the ResultSet object.
Which methods of these to use depends on the scrolling you have selected when
you created the PreparedStatement object.

When a row in the ResultSet is accessible several ResultSet
methods can be used to update column data.

Here is the most used:

Methods in ResultSet interface

Description

void updateDouble(int, double)
void updateDouble(String, double)

Updates a double in the column with number (1.. N) or database
table defined column name.

void updateFloat(int, float)
void updateFloat(String, float)

Updates a float in the column with number (1.. N) or database
table defined column name.

void updateInt(int, int)
void updateInt(String, int)

Updates an int in the column with number (1.. N) or database
table defined column name.

void updateLong(int, long)
void updateLong(String, long)

Updates a long in the column with number (1.. N) or database
table defined column name.

void updateShort(int, short)
void updateShort(String, short)

Updates a short in the column with number (1.. N) or database
table defined column name.

void updateString(int, String)
void updateString(String, String)

Updates a String in the column with number (1.. N) or database
table defined column name.

void updateTime(int, Time)
void updateTime(String, Time)

Updates a Time in the column with number (1.. N) or database
table defined column name.

void updateDate(int, Date)
void updateDate(String, Date)

Updates a Date in the column with number (1.. N) or database
table defined column name.

Updates a Object in the column with number (1.. N) or database
table defined column name. The last parameter is for a BigDecimal ,
the number of digits after the decimal point an
for Java Object types InputStream and Reader, this is the length
of the data in the stream or reader.

void updateRowId(int, RowId)
void updateRowId(String, RowId)

Updates a RowId in the column with number (1.. N) or database
table defined column name.

Updates a Reader containing the column value using the
column number (1.. N) or database
table defined column name.

When you have updated the columns as required,
(depending on the Database table Column definition)
you must use the void updateRow() method to
update the database table. This method cannot be called when the cursor is on the insert row.

If you may decide that you don’t want to update the row,
you can call the void cancelRowUpdates() method instead.

Example of updating data in a ResultSet table using a PrearedStatement object: