随笔-295  评论-26  文章-1  trackbacks-0
try{  
          ……      
          con.setAutoCommit(false);  
          ……     //执行你的任务  
          ……  
          con.commit();  
          con.setAutoCommit(true);  
   
  }catch(SQLException   ex)   {  
          System.err.println("SQLException:   "   +   ex.getMessage());  
                  if   (con   !=   null)   {  
      try   {  
          System.err.print("Transaction   is   being   ");  
          System.err.println("rolled   back");  
          con.rollback();  
        }   catch(SQLException   excep)   {  
  System.err.print("SQLException:   ");  
  System.err.println(excep.getMessage());  
  }  
  }  
  }
finaly{
try{
if(con   !=   null){
con.close();
}
setAutoCommit(false)之后,你必须手工调用commit   或者   rollback来确认事务是提交还是回滚  
  最好再调用setAutoCommit(true)来关闭事务状态再close连接

大盘预测 国富论
posted on 2009-02-13 11:42 华梦行 阅读(397) 评论(0)  编辑  收藏 所属分类: JDK

只有注册用户登录后才能发表评论。


网站导航: