Local transactions using JDBC 2.0 API.

ENTERPRISE JAVA
Transaction Processing With Java
Salih Ergül
Listing 1. Local transactions using JDBC 2.0 API.


// First get a connection, assuming that ds is of type
// DataSource
Connection con = ds.getConnection(...);

// Do all the work as a single transaction
con.setAutoCommit(false);

// The actual work goes here. You can query and update
// multiple tables in the database

// Commit the transaction
con.commit();

// Close the connection
con.close();