mysql5 不发生异常时功能正常,有异常时,不回滚
public void copyInfoToEditPublishFromGather(String id){
String sql = " INSERT INTO table_edit_information" +
" (information_title, information) " +
" select " +
" information_title , information" +
" from table_gather_information" +
" WHERE ID = " +id ;
String sqlUpdateEdit = "UPDATE table_edit_information SET publish = 1 WHERE id_gather = " + id;
String sqlUpdateGather = "UPDATE table_gather_information SET use_status = 1 WHERE ID = " + id;
try{
conn.setAutoCommit(false);
PreparedStatement psmt = conn.prepareStatement(sql);
psmt.executeUpdate();
psmt = null;
psmt = conn.prepareStatement(sqlUpdateEdit);
//psmt.addBatch();
psmt.executeUpdate();
psmt = null;
psmt = conn.prepareStatement(sqlUpdateGather);
psmt.addBatch();
psmt.executeUpdate();
//psmt.executeUpdate(sqlUpdateEdit);
//psmt.executeUpdate(sqlUpdateGather);
conn.commit(); //提交事务
psmt.close();
conn.close();
}catch(Exception e) {
try{
conn.rollback();
}catch(SQLException r){
System.out.println(r.getMessage());
}
System.out.println(e.getMessage());
}
}
------解决方案--------------------------------------------------------
try{
conn.rollback();
}catch(SQLException r){
System.out.println(r.getMessage());
去掉这里的try/catch
------解决方案--------------------------------------------------------
try{
在这里打印一下看看他有没有进来
conn.rollback();
}catch(SQLException r){
System.out.println(r.getMessage());
}