Transaction Management
About
1. Basics of JDBC Transactions
Connection conn = dataSource.getConnection();
try {
conn.setAutoCommit(false); // start transaction
// Execute multiple SQL statements
PreparedStatement stmt1 = conn.prepareStatement("INSERT INTO employee ...");
stmt1.executeUpdate();
PreparedStatement stmt2 = conn.prepareStatement("UPDATE salary ...");
stmt2.executeUpdate();
conn.commit(); // commit if everything succeeds
} catch (SQLException e) {
conn.rollback(); // rollback on any failure
throw e;
} finally {
conn.setAutoCommit(true); // restore default behavior
conn.close();
}2. Spring JDBC Transaction Management
Important Points
Common Mistakes to Avoid
When to Use JDBC-level Transactions ?
Last updated