Change ResultSets

With the iSeries™ JDBC drivers, you can change ResultSets by performing several tasks.

The default setting for ResultSets is read only. However, with Java™ Database Connectivity (JDBC) 2.0, the iSeries JDBC drivers provide complete support for updateable ResultSets.

You can refer to ResultSet concurrency on how to update ResultSets.

Update rows

Rows may be updated in a database table through the ResultSet interface. The steps involved in this process are the following:

  1. Change the values for a specific row using various update<Type> methods, where <Type> is a Java data type. These update<Type> methods correspond to the get<Type> methods available for retrieving values.
  2. Apply the rows to the underlying database.

The database itself is not updated until the second step. Updating columns in a ResultSet without calling the updateRow method does not make any changes to the database.

Planned updates to a row can be thrown away with the cancelUpdates method. Once the updateRow method is called, changes to the database are final and cannot be undone.

Note: The rowUpdated method always returns false as the database does not have a way to point out which rows have been updated. Correspondingly, the updatesAreDetected method returns false.

Delete rows

Rows may be deleted in a database table through the ResultSet interface. The deleteRow method is provided and deletes the current row.

Insert rows

Rows may be inserted into a database table through the ResultSet interface. This process makes use of an "insert row" which applications specifically move the cursor to and build the values they want to insert into the database. The steps involved in this process are as follows:

  1. Position the cursor on the insert row.
  2. Set each of the values for the columns in the new row.
  3. Insert the row into the database and optionally move the cursor back to the current row within the ResultSet.
Note: New rows are not inserted into the table where the cursor is positioned. They are typically added to the end of the table data space. A relational database is not position-dependent by default. For example, you should not expect to move the cursor to the third row and insert something that shows up before the forth row when subsequent users fetch the data.

Support for positioned updates

Besides the method for updating the database through a ResultSet, SQL statements can be used to issue positioned updates. This support relies on using named cursors. JDBC provides the setCursorName method from Statement and the getCursorName method from ResultSet to provide access to these values.

Two DatabaseMetaData methods, supportsPositionedUpdated and supportsPositionedDelete, both return true as this feature is supported with the native JDBC driver.

See Example: Change values with a statement through another statement's cursor for more information.

See Example: Remove values from a table through another statement's cursor for more information.

Related concepts
ResultSet characteristics
Cursor movement
Retrieve ResultSet data
Create ResultSets
Related reference
Example: ResultSet interface for IBM Developer Kit for Java