首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

请教各位,使用PreparedStatement mysql 数据库 不回滚,盼望解答。多谢。 具体如上

2012-08-16 
请问各位,使用PreparedStatementmysql 数据库 不回滚,盼望解答。谢谢。 具体如下:mysql5不发生异常时功能正

请问各位,使用PreparedStatement mysql 数据库 不回滚,盼望解答。谢谢。 具体如下:
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()); 
}

热点排行