save point
import java.sql.SQLException;
import java.sql.Savepoint;
import java.sql.Statement;
public class SavePoint {
/**
* @param args
* @throws ClassNotFoundException
* @throws SQLException
*/
public static void main(String[] args) throws SQLException, ClassNotFoundException {
testSavePoint();
}
private static void testSavePoint() throws SQLException, ClassNotFoundException{
String sql1 = "update user set address = 'test3' where id = 1";
String sql2 = "update user set address = 'test4' where id > 3";
Statement st = JdbcMySqlUtil.getInstance().getStatement() ;
st.getConnection().setAutoCommit(false);
Savepoint sp ;
st.executeUpdate(sql1);
sp = st.getConnection().setSavepoint();
st.executeUpdate(sql2);
st.getConnection().rollback(sp);
st.getConnection().commit() ;
JdbcMySqlUtil.free(null, st, st.getConnection());
}
}