Savepoint Support

You can use the Savepoint interface, which contains methods to set, release, or roll back a transaction to designated savepoints.

  • Using Savepoints in your transactions – n JDBC 3.0, the Savepoint interface allows you to partition a transaction into logical breakpoints, providing control over how much of the transaction gets rolled back.
  • Setting and rolling back to a Savepoint – JDBC 3.0 API includes the method Connection.setSavepoint, which sets a savepoint within the current transaction and returns a Savepoint object. The Connection.rollback method is overloaded to take a Savepoint object argument.
  • Releasing a Savepoint – The Connection.releaseSavepoint method takes a Savepoint object as a parameter and removes it from the current transaction.

    After a Savepoint has been released, if you try to reference it in a rollback operation, a SQLException occurs. Any savepoints you create in a transaction are automatically released and become invalid when the transaction is committed or when the entire transaction is rolled back. If you roll a transaction back to a savepoint, it automatically releases and invalidates any other savepoints that were created after the savepoint in question.

    Note: You can use the DatabaseMetaData.supportsSavepoints method to determine whether a JDBC API implementation supports savepoints.