On this page
- Create a DAO method in which you set JDBC connection’s auto-commit property to false
dbConn.setAutoCommit(false);
- Execute all your queries
stmt = dbConn.createStatement();
result = stmt.executeQuery(query);
stmt.executeUpdate(update);
- Commit or rollback the transaction
dbConn.commit();
- Reset auto-commit to true again for other execution
dbConn.setAutoCommit(true);
This is really simple, as it should be for something purely mechanical. The challenge for every programmer is how to write your transaction code or order your queries such that you can achieve desired result.