说的不详细,用事务控制不行吗,try{
  conn.setAutoCommit(false)
  插入第一条数据
  插入第二条数据
  conn.commit()
}catch(SQLException e){
  //出现异常,进行回滚操作,打印出异常信息 
  e.printStackMessage();
  conn.rollback()
}finally{
   关闭连接,陈述语句等各种资源
}

解决方案 »

  1.   

    to(shaxixi)就是要用事务控制,刚看你写的好像和数据库操作放在一起了,分开写可以吗?
      

  2.   

    public static void executeUpdate(String sqlId, String[] params) throws DataAccessAppException, DataAccessSysException
    {
    int effectrows = 0; Connection connection = null; PreparedStatement statement = null; try
    {

    connection = DbAccessor.getConnection();
    connection.setAutoCommit(false);
    String sql = DbUtil.getSQL(sqlId);
    statement = connection.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
    processPSPrama(statement, params);
    effectrows = statement.executeUpdate(); if(effectrows <= 0 && DbUtil.isExsitNotDeleteOpr(sqlId))
    {
    DbAccessor.rollback(connection); throw new RecordNotFoundAppException("Error.Db.DataAccessFail");
    }
    connection.commit(); connection.setAutoCommit(true);
    }
    catch(SQLException e)
    {

    DbAccessor.rollback(connection); _log.error(e.getMessage(), e); SqlExceptionHandler sqlExceptionHandler = OracleExceptionHandler.getInstance(); sqlExceptionHandler.execute(e);
    }
    catch(DataAccessSysException e)
    {

    DbAccessor.rollback(connection); throw e;
    }
    finally
    {

    DbAccessor.close(null, statement, connection);
    }
    }
    这样写好之后,在业务层去调用就行了,是吗?