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, and ResultSet objects returned from Statement.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 the Statement object.

  • A Statement that returns a ResultSet defers committing the transaction, so iteration over the ResultSet 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 associated ResultSet.

If auto-commit is off
  • You can have as many ResultSet objects as you need, provided each ResultSet comes from a unique Statement instance.

  • You cannot have multiple open ResultSet objects from the same Statement.

    • When a Statement is executed, any currently associated ResultSet is closed and cannot be reopened or reused in any way.