JDBC ResultSet
JDBC ResultSet is a table of data returned by a SQL query executed on a database.
JDBC ResultSet Behavior
The following table compares the behavior of ResultSet depending on AutoCommit.
AutoCommit is configured using the setAutoCommit() method on the connection object.
| AutoCommit ON | AutoCommit OFF | |
|---|---|---|
Transaction commit |
Transaction commit happens automatically after each statement. For statements that return a ResultSet, commit is deferred until iteration is complete. |
Transaction commit happens only with manual commit. |
Number of active |
One active |
Multiple active |
|
Metadata is valid as long as the associated |
Metadata valid as long as the associated |
Iteration over |
A |
Iteration over the |
JDBC ResultSet Holdability
By default, a ResultSet created within a transaction is closed after the transaction is committed to the database.
To prevent the ResultSet from getting closed and to hold it open after the transaction has been committed, set the setHoldability property to HOLD_CURSORS_OVER_COMMIT.
For example:
Connection conn = dataSource.getConnection();
conn.setHoldability(ResultSet.HOLD_CURSORS_OVER_COMMIT);
As a result of using the HOLD_CURSORS_OVER_COMMIT value, the ResultSet is materialized in memory.
To facilitate queries with ResultSet that exceed memory available, NuoDB provides Spill to Disk capability.
If Spill to Disk is enabled and the ResultSet exceeds the DISKSPILL_MEMORY_THRESHOLD_MB system property, the ResultSet will be written to disk on the Transaction Engine (TE).
For more information on Spill to Disk in NuoDB, see Spill to Disk.