I'm using JDBC but I got some problems with rollback and savepoint. I can't understand why this code actually doesn't rollback to the savepoint and the record inserted remains.
try {
conn.setAutoCommit(false);
stmt = conn.createStatement();
sp = conn.setSavepoint();
stmt.executeUpdate("INSERT INTO test(id) VALUES(" + args[0] + ")");
if(true) {
conn.rollback(sp);
System.out.println("rollback");
}
} catch (SQLException ex) {
// handle any errors
System.out.println("SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
System.out.println("rollback");
conn.rollback(sp);
} finally {
conn.commit();
}
Thanks in advance.