就这里有问题,明明是多个记录,但只执行一次    
                      while(rs2.next()){                           
                             bookid = rs2.getString("bookid").trim();
  
                             m = rs2.getInt("num");    //定购数量
                             if(sales==1){
                               sql = "update bookinfo set nownum = nownum - "+ m +" where bookid ='"+bookid+"' "; 
                             }else {
                                   sql = "update bookinfo set nownum = nownum + "+ m +" where bookid ='"+bookid+"' ";
  
                            }
                            stmt.execute(sql);   //好像这里有问题,跳出while循环了
                       
                         
                        }

解决方案 »

  1.   

    while(rs2.next()){                           
                                 bookid = rs2.getString("bookid").trim();
      
                                 m = rs2.getInt("num");    //定购数量
                                 if(sales==1){
                                   sql = "update bookinfo set nownum = nownum - "+ m +" where bookid ='"+bookid+"' ";
                                 }else {
                                       sql = "update bookinfo set nownum = nownum + "+ m +" where bookid ='"+bookid+"' ";
      
                                }
                          System.out.println(sql);//把sql打印出来有好处,在数据库里直接执行这条sql
                                stmt.execute(sql);   //好像这里有问题,跳出while循环了
                           System.out.println("execute ok");//在这里打印一下
                      }
                            rs2.close();
                            return true;
                    }
                    catch (Exception e)
                    {
                            System.out.println(e.toString());//在这里打印错误
                            return false;
                    }
      

  2.   

    sqlStr语句没有问题,是连续使用stmt的问题
    stmt.execute(sql); //是不是连续使用stmt会引起错误
    我是这样定义的
            DBConnectionManager dcm = new DBConnectionManager();
            Connection conn = dcm.getConnection();
            Statement stmt=conn.createStatement();
            Statement stmt2=conn.createStatement();
      

  3.   

    catch (Exception e)
                    {
                            System.out.println(e.toString());//在这里打印错误
                            return false;
                    }错误提示:
    java.sql.SQLException: [Microsoft][ODBC 驱动程序管理器] 无效的游标状态
      

  4.   

    上面的错误提示应该是:
    java.lang.NullPointerException