import java.sql.*; public class Transaction2 { public static void main(String[] args) { Statement stmt = null; Connection conn = null; try { Class.forName(""); conn = DriverManager.getConnection(""); conn.setAutoCommit(false); stmt = conn.createStatement(); stmt.addBatch(sql); conn.setAutoCommit(true); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { try { if(conn != null) { conn.rollback(); conn.setAutoCommit(true); } } catch (SQLException e1) { e.printStackTrace(); } } finally { try { if(stmt != null) { stmt = null; stmt.close(); } if(conn != null) { conn = null; conn.close(); } } catch (SQLException e) { e.printStackTrace(); } } } }