【发布时间】:2017-11-05 13:43:53
【问题描述】:
java.sql.Connection.commit() 有一些我不明白的地方。
我使用 Derby(Java DB) 作为数据库服务器。
当我执行 setAutoCommit(false) 时,我希望我的查询在我明确调用 commit() 方法之前不起作用。 但实际上,即使我不调用 commit(),它仍然会提交。 当我在我的表上调用 select * 来打印内容时,即使我没有明确提交查询,我也可以看到已添加行。
有人能给我解释一下吗?
con.setAutoCommit(false);
PreparedStatement updateHair = null;
PreparedStatement addMan = null;
try {
String updateString =
"update PERSONNE " +
"set haircolor = 'RED' where haircolor = 'SHAVE'";
String updateStatement =
"insert into personne values " +
"(3,'MICHEL','SHAVE')";
addMan = con.prepareStatement(updateStatement);
addMan.executeUpdate();
updateHair = con.prepareStatement(updateString);
updateHair.executeUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
【问题讨论】: