日期:2014-05-17  浏览次数:20836 次

oracle 事务处理问题
有以下语句,请问对于事务处理这块儿,如果i>0不成立,即con.commit();没执行。对程序有什么影响?
异常方面的影响。。。数据库菜鸟。。。求解释。。。
 try{
       con = dataSource.getConnection();
       con.setAutoCommit(false);
       String sql ="";
       pst = con.prepareStatement(sql);
       int i = pst.executeUpdate();
       if(i>0){
          bool = true;
          con.commit();
       }
     }catch (Exception e){
       con.rollback();
       throw e;
    }finally{
       con.setAutoCommit(true);
       DBUtil.freeConnection(rs, pst, con);
    }
oracle 事务处理 异常

------解决方案--------------------
对数据没影响,因为没有更新到数据。当然也没有抛出异常,所以异常块也不会被捕获到。


executeUpdate

int executeUpdate()
                  throws SQLException
在此 PreparedStatement 对象中执行 SQL 语句,该语句必须是一个 SQL 数据操作语言(Data Manipulation Language,DML)语句,比如 INSERT、 UPDATE 或 DELETE 语句;或者是无返回内容的 SQL 语句,比如 DDL 语句。
返回:
(1) SQL 数据操作语言 (DML) 语句的行数 (2) 对于无返回内容的 SQL 语句,返回 0
抛出:
SQLException - 如果发生数据库访问错误,在关闭的 PreparedStatement 上调用此方法,或者 SQL 语句返回一个 ResultSet 对象