下面有一个方法 得到数据库的连接,并且我把AutoCommit设为false,
private Connection getCon() {
Connection con = null;
try {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection(url, user, password);
con.setAutoCommit(false);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return con;
}
然后我这里有个数据更新的操作
...
conn=getCon();
String updateSql = "update sys_admin set admin_password = ? where admin_id = ? and admin_password = ?";
pstmt = conn.prepareStatement(updateSql);
pstmt.setString(i++, newPwd);
pstmt.setLong(i++, adminId);
pstmt.setString(i++, oldPwd);
if(pstmt.executeUpdate() == 1){
//执行到这里的时候数据已经在数据库里更新了,
return MessageCode.SUCCESS;
}
....
请问我没有conn.commit()之前数据就已经更新了吗?;