Connection.releaseSavepoint(Savepoint savepoint)
Releases the specified savepoint, and all subsequently established savepoints.
Connection.rollback(Savepoint savepoint)
Rolls back work to the specified savepoint.
DatabaseMetaData.supportsSavepoints()
Indicates whether a data source supports savepoints.
The following example demonstrates how to set a savepoint, roll back to the
savepoint, and release the savepoint.
Related tasks
“Committing or rolling back JDBC transactions” on page 74
Related reference
“Data types that map to database data types in Java applications” on page 193
Retrieving automatically generated keys in JDBC applications
With the IBM Data Server Driver for JDBC and SQLJ, you can retrieve
automatically generated keys (also called auto-generated keys) from a table using
JDBC 3.0 methods.
Automatically generated keys correspond to the contents of an identity column. An
identity column is a table column that provides a way for the data source to
automatically generate a numeric value for each row. You define an identity
column in a CREATE TABLE or ALTER TABLE statement by specifying the AS
IDENTITY clause when you define a column that has an exact numeric type with a
scale of 0 (SMALLINT, INTEGER, BIGINT, DECIMAL with a scale of zero, or a
distinct type based on one of these types).
To enable retrieval of automatically generated keys from a table, you need to
indicate when you insert rows that you will want to retrieve automatically
generated key values. You do that by setting a flag in a
Connection.prepareStatement, Statement.executeUpdate,orStatement.execute
Connection con;
Statement stmt;
ResultSet rs;
String empNumVar;
int shoeSizeVar;
...
con.setAutoCommit(false); // set autocommit OFF
stmt = con.createStatement(); // Create a Statement object
... // Perform some SQL
con.commit(); // Commit the transaction
stmt.executeUpdate("INSERT INTO EMP_SHOE " +
"VALUES ('000010', 6)"); // Insert a row
Savepoint savept = con.setSavepoint(); // Create a savepoint
...
stmt.executeUpdate("INSERT INTO EMP_SHOE " +
"VALUES ('000020', 10)"); // Insert another row
conn.rollback(savept); // Roll back work to the point
// after the first insert
...
con.releaseSavepoint(savept); // Release the savepoint
stmt.close(); // Close the Statement
Figure 17. Setting, rolling back to, and releasing a savepoint in a JDBC application
58 Application Programming Guide and Reference for Java
™