和数据库有关希吗?
sqlserver2000

解决方案 »

  1.   

    Now I tell you some method:
    Connection cx = null;   public void rollback()
        {
            try
            {
                cx.rollback();
                cx.setAutoCommit(true);
            }
            catch (Exception e)
            {
                ;
            }
        }
        public void begin()
        {
            try
            {
                cx.setAutoCommit(false);
            }
            catch (Exception e)
            {
                sysLog.log(e, "begin");
            }
        }
       public void commit()
        {
            try
            {
                cx.commit();
                cx.setAutoCommit(true);
            }
            catch (Exception e)
            {
                sysLog.log(e, "commit");
            }
        }
    在update table这前用begin();
    update 出错,就rollback()
    update 没有出错commit;
    注意一定是同一个rs.....
    好运与你同行
      

  2.   

    看出错提示:
    你的rs是依赖于stat得到的,而stat初始化是的con并没有被setAutoCommit(false),但是你在对rs操作的过程中执行了setAutoCommit(false),所以出错,试试这个:try{
             Connection con;
             con = DriverManager.getConnection( YOUR_DRIVER,YOUR_DB_NAME,YOUR_DB_PASSWORD );
             con.setAutoCommit(false);
    Statement stat;
    stat=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
    ResultSet rs=null;
    ResultSet rs1=null;
    rs=stat.executeQuery("select * from table1);
             rs.moveToInsertRow();
    rs.updateInt("Id",1);
    rs.updateString("Name","aaa");
    rs.insertRow();                   //出错行
             rs1=stat.executeQuery("select * from table2);
             rs1.moveToInsertRow();
    rs1.updateInt("Id",1);
    rs1.updateString("Name","bbb");
    rs1.insertRow();
             con.commit();
    }catch(SQLException sex){
         try{
             con.rollback();
         }catch(Exception ex){}
    }finally{
       try{
        con.close();
       }catch(Exception ex1){}
    }