Working with Result Sets
ResultSet Longevity
A ResultSet behaves differently depending on whether the autocommit property is set on or off.
- If auto-commit is on
-
-
You are limited to one active, valid
ResultSet. -
Associated
ResultSetMetaDataobjects, andResultSetobjects returned fromStatement.getGeneratedKeys()can also be open at the same time but have the same "shelf life" - they are valid until closed, committed, or another statement is executed by theStatementobject. -
A
Statementthat returns aResultSetdefers committing the transaction, so iteration over theResultSetis consistent with the data and the transaction isolation level. -
Each execution of a
Statementwill commit any previously deferred transaction and so closes any associatedResultSet.
-
- If auto-commit is off
-
-
You can have as many
ResultSetobjects as you need (up to a maximum of 1000), provided eachResultSetcomes from a uniqueStatementinstance. -
You cannot have multiple open
ResultSetobjects from the sameStatement.-
When a
Statementis executed, any currently associatedResultSetis closed and cannot be reopened or reused in any way.
-
-
Setting Result Set Holdability
By default, a result set created within a transaction is closed after the transaction is committed to the database.
It is sometimes useful for the result set to be held open after the transaction has been committed.
To prevent the result set from being closed, set the holdability property to HOLD_CURSORS_OVER_COMMIT:
Connection conn = dataSource.getConnection();
conn.setHoldability(ResultSet.HOLD_CURSORS_OVER_COMMIT);
As a result of using the HOLD_CURSORS_OVER_COMMIT value, the result set is materialized in-memory.
To facilitate queries with result sets that exceed memory available, NuoDB provides Spill to Disk capability.
If Spill to Disk is enabled and the result set exceeds the DISKSPILL_MEMORY_THRESHOLD_MB value, the result set will be written to disk on the Transaction Engine (TE).
For more information on Spill to Disk in NuoDB, see Spill to Disk.