What Is ResultSet Holdability? in JDBC

JDBC 3.0 adds support for specifying result set (or cursor) holdability. Result set holdability is the ability to specify whether cursors (or a result set as java.sql.ResultSet objects) should be held open or closed at the end of a transaction. A holdable cursor, or result set, is one that does not automatically close when the transaction that contains the cursor is committed. You may improve database performance by including the ResultSet holdability. If ResultSet objects are closed when a commit operation is implicitly or explicitly called, this can also improve performance.

According to Java Database Connectivity, Version 3.0:

When the method Connection.commit is called, open ResultSet objects that have been created during the current transaction are closed.With ResultSet holdability, it is possible to exercise greater control on when the ResultSet objects are closed when the commit operation is performed. Using the ResultSet holdability, ResultSet objects that are closed when a commit operation is performed can result in better performance in some applications.

To specify the holdability of a ResultSet object, you must do so when preparing a java.sql.Statement (or java.s ql. Prepared Statement or java. sql. Callable Statement) using the Connection. create Statement(), Connection. prepare Statement(), or Connection. prepareCall() method. The ResultSet holdability may be one of the following constants (defined in the ResultSet interface):

  • HOLD_CURSORS_OVER_COMMIT: The constant indicating that ResultSet objects should not be closed when the method Connection.commit() is called.
  • CLOSE_CURSORS_AT_COMMIT: The constant indicating that ResultSet objects should be closed when the method Connection.commit() is called.

In general, closing a cursor(as a ResultSet object) when a transaction is committed results in better performance.



All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

JDBC Topics