9

Reading

http://download.oracle.com/javase/6/docs/api/java/sql/Savepoint.html

it is not well spelled out what savepoints are mapped from database perspective.

When savepoints are set, are the database changes made available to other transactions?

Thanks

gliptak
  • 3,592
  • 2
  • 29
  • 61

2 Answers2

19

A savepoint marks a point that the current transaction can roll back to. Instead of rolling all of its changes back, it can choose to roll back only some of them. For example, suppose you:

  • start a transaction,
  • insert 10 rows into a table,
  • set a savepoint,
  • insert another 5 rows,
  • rollback to the savepoint,
  • commit the transaction.

After doing this, the table will contain the first 10 rows you inserted. The other 5 rows will have been deleted by the rollback.

Setting a savepoint doesn't 'save' any data to the database. It doesn't make database changes visible to any other transaction. A savepoint is just a marker that the current transaction can roll back to.

Luke Woodward
  • 63,336
  • 16
  • 89
  • 104
6

Savepoints are not a JDBC feature, they are a DBMS feature.

In addition to Luke's detailed answer you might also want to read up on what the DBMS manuals explain about savepoints

http://www.postgresql.org/docs/current/static/sql-savepoint.html
http://download.oracle.com/docs/cd/E11882_01/server.112/e17118/statements_10001.htm#BABFIJGC
http://publib.boulder.ibm.com/infocenter/db2luw/v9r7/topic/com.ibm.db2.luw.sql.ref.doc/doc/r0003271.html
http://msdn.microsoft.com/en-us/library/ms188378.aspx
http://dev.mysql.com/doc/refman/5.5/en/savepoint.html

  • This is wrong. As stated on [http://docs.oracle.com/](http://docs.oracle.com/javase/tutorial/jdbc/basics/transactions.html#set_roll_back_savepoints) `The method Connection.setSavepoint, sets a Savepoint object within the current transaction. The Connection.rollback method is overloaded to take a Savepoint argument.` – Valentino Dell'Aica Sep 26 '12 at 08:20
  • 3
    @ValentinoDell'Aica: so what is wrong in my statement? Savepoints **are** a DBMS feature. The JDBC API simply gives you access to that feature. If the DBMS doesn't support them, there is no way you can use them from within JDBC –  Sep 26 '12 at 08:26