You can use the Savepoint interface, which contains methods to set, release, or roll back a transaction to designated savepoints.
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.