Holdable result sets

The holdable result set feature permits an application to keep result sets open after implicit or explicit commits. By default, the cursor controlled by the result set is held open after a commit.

Note: Derby, supports non-holdable result sets on platforms which support JDBC 3.

Starting with Java 2 Platform, Standard Edition, v 1.4 (J2SE), result sets can be created with close when a commit occurs option. Such result sets will be automatically closed when a commit happens. Result sets are automatically closed when a transaction aborts, whether or not they have been specified to be held open.

To specify whether a result set should be held open after a commit takes place, supply one of the following ResultSet parameters to the Connection method createStatement, prepareStatement, or prepareCall:

The method Statement.getResultSetHoldability() indicates whether a result set generated by the Statement object stays open or closes, upon commit. See the Java DB Reference Manual for more information.

When an implicit or explicit commit occurs, result sets that hold cursors open behave as follows:

When a rollback or rollback to savepoint occurs, either explicitly or implicitly, the following behavior applies:
  • All open result sets are closed.
  • All locks acquired during the unit of work are released.
Note: Holdable result sets do not work with XA transactions in Derby. When working with XA transactions, the result set should be opened with holdability ResultSet.CLOSE_CURSORS_AT_COMMIT.
Related concepts
Transactions when auto-commit is disabled
Updatable result sets
Result sets and auto-commit
Scrollable result sets
Related reference
Simple non-updatable result sets