# Updatable result sets

Updatable result sets in Derby can be updated by using result set update methods (`updateRow()`,`deleteRow()` and `insertRow()`), or by using positioned update or delete queries.

Both scrollable and non-scrollable result sets can be updatable in Derby.

If the query which was executed to create the result set is not updatable, Derby will downgrade the concurrency mode to `ResultSet.CONCUR_READ_ONLY`, and add a warning about this on the `ResultSet`. The compilation of the query fails if the result set cannot be updatable, and contains a `FOR UPDATE` clause.

Positioned updates and deletes can be performed if the query contains `FOR UPDATE` or if the concurrency mode for the result set is `ResultSet.CONCUR_UPDATABLE`.

To use the result set update methods, the concurrency mode for the result set must be `ResultSet.CONCUR_UPDATABLE`. The query does not need to contain `FOR UPDATE` to use these methods.

Updatable cursors lock the current row with an update lock when positioned on the row, regardless of isolation level. Therefore, to avoid excessive locking of rows, only use concurrency mode `ResultSet.CONCUR_UPDATABLE` or the `FOR UPDATE` clause when you actually need to update the rows. For more information about locking, see Types and scope of locks in Derby systems.

- Requirements for updatable result sets
  Only specific SELECT statements- simple accesses of a single table-allow you to update or delete rows as you step through them.
- Forward only updatable result sets
  A forward only updatable result set maintains a cursor which can only move in one direction (forward), and also update rows.
- Scrollable updatable result sets
  A scrollable updatable result set maintains a cursor which can both scroll and update rows.
- Inserting rows with updatable result sets
  Updatable result set can be used to insert rows to the table, by using ResultSet.insertRow().
- Naming or accessing the name of a cursor
  There is no SQL language command to assign a name to a cursor. You can use the JDBC setCursorName method to assign a name to a ResultSet that allows positioned updates and deletes.
- Extended updatable result set example

Parent topic: Result set and cursor mechanisms
Related concepts
Result sets and auto-commit
Scrollable result sets
Related reference
Simple non-updatable result sets
Holdable result sets