ResultSet Shelf Life
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
ResultSetMetaData
objects, andResultSet
objects 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 theStatement
object. -
A
Statement
that returns aResultSet
defers committing the transaction, so iteration over theResultSet
is consistent with the data and the transaction isolation level. -
Each execution of a
Statement
will commit any previously deferred transaction and so closes any associatedResultSet
.
-
- If auto-commit is off
-
-
You can have as many
ResultSet
objects as you need, provided eachResultSet
comes from a uniqueStatement
instance. -
You cannot have multiple open
ResultSet
objects from the sameStatement
.-
When a
Statement
is executed, any currently associatedResultSet
is closed and cannot be reopened or reused in any way.
-
-