简体   繁体   中英

SQL JDBC java commits when auto-commit is off

My intention is to try out SQL Rollback with the program exit halfway without finishing.I had the following connection in my program. However data still written to the database even when I did not set any con.commit upon exiting halfway. I did a debug mode, it fall into the exception and execute the con.rollback(); but in which is did not rollback. Which made me quite confuse.

con = DriverManager.getConnection(value);
con.setAutoCommit(false);
try{
pstmt = con.prepareStatement("CREATE TABLE IF NOT EXISTS Test (Number varchar(255))")
pstmt.execute();
pstmt = con.prepareStatement("INSERT INTO `Test` (Number) values (?)");
pstmt.setString(1,"1");
pstmt.executeUpdate();
}catch(Exception){
con.rollback();
}

它取决于数据库,例如在Oracle Create table中...或任何DDL执行隐式提交,此提交之前的所有操作都无法回滚

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM