日期:2014-05-18  浏览次数:20726 次

高手帮忙看看这段程序那里错了,谢谢了!
String   amount=codeToString(request.getParameter( "amount "));
  String   sqlString2= "select   *   from   qicaiTable   where   e_name= ' "+e_name+ " 'and   e_size= ' "+e_size+ " ' ";
  try  
        {   Connection   con1;
            Statement   sql1;
            ResultSet   rs1;
            Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver ");
            con1=DriverManager.getConnection( "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=shangdianDB ", "sa ", " ");
            sql1=con1.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
    rs1=   sql1.executeQuery(sqlString2);
    if(rs1.next()){
    String   temp=rs1.getString( "amount ");
    int   amount1=Integer.parseInt(temp)-Integer.parseInt(amount);
    if(amount1 <0){
    out.print( " <script> ");
            out.print( "alert( '你输入的数量超过库存量,请重新输入! '); ");
            out.print( "window.location.href= '/shd/send.jsp '; ");
            out.print( " </script> ");
    }
    else
            sql1.executeQuery( "update   qicaiTable   set   amount= ' "+amount1+ " '   where   e_name= ' "+e_name+ " ' ");
    }
    else{
    out.print( " <script> ");
            out.print( "alert( '没有你要的商品,请重新输入! '); ");
            out.print( "window.location.href= '/shd/send.jsp '; ");
            out.print( " </script> ");
    }
   
          con1.close();
    //response.sendRedirect( "xianshi.jsp ");
    }
  catch(SQLException   e1)  
        {
            out.print(e1);
        }
}
    %>


当amount1 <0时不执行if()语句,但是当amount> 0时执行   sql1.executeQuery()语句。看了半天了不知道那里错了,请高手指点下!


------解决方案--------------------
if(amount1 <0){
out.print( " <script> alert( '你输入的数量超过库存量,请重新输入! '); </script> ");
}
else
{
sql1.executeQuery( "update qicaiTable set amount= ' "+amount1+ " ' where e_name= ' "+e_name+ " ' ");
}
}
else{
out.print( " <script> alert( '没有你要的商品,请重新输入! '); </script> ");
}
先这样试试,如果正常的话再加跳转语句