// 获得数据库连接 Connection conn = getDbConnection(......);boolean autoCommit = true;try{ // get the connection's original auto-commit status. autoCommit = conn.getAutoCommit(); conn.setAutoCommit(false); // some business logic, etc. ...
conn.commit(); }catch(SQLException sqlEx){ conn.rollback(); // do something for exception ... }finally{ try{ // restore the connection's original auto-commit status. conn.setAutoCommit(autoCommit); conn.close(); }catch(SQLException sqlEx){ // do something for exception ... } conn = null; }
试一下在数据库更新代码后加一句"conn.commit()",看看行不行
// 获得数据库连接
Connection conn = getDbConnection(......);boolean autoCommit = true;try{
// get the connection's original auto-commit status.
autoCommit = conn.getAutoCommit(); conn.setAutoCommit(false); // some business logic, etc.
...
conn.commit();
}catch(SQLException sqlEx){
conn.rollback();
// do something for exception
...
}finally{
try{
// restore the connection's original auto-commit status.
conn.setAutoCommit(autoCommit); conn.close();
}catch(SQLException sqlEx){
// do something for exception
...
}
conn = null;
}
发现是自己用错了一个函数
stmt.executeBatch()这个函数应该是用stmt.executeUpdate(),对吧
验证后结果正确.