以下是本人的代码,从另一个页面表单提交获得选中的复选框的值,若选中获得对应的id值
删除id对应的记录
<%
       int count=newsPage.getCurrentPageSize();  //当页复选框数目
       ArrayList<Integer> IDS=new ArrayList<Integer>();
       for(int i=0;i<count;i++)
       {
        int num=i+1;
        String value=request.getParameter(String.valueOf(num));//得到复选框的值
           if(value!=null&&value.toLowerCase().equals("on"))
           {
          int id=Integer.parseInt(request.getParameter("checkBox"+num));
          IDS.add(new Integer(id));
           }
       }
        Connection con=db.getConnection();
        int j=0;
        if(con!=null)
        {
           String sql="DELETE FROM NEWS WHERE ";
         Statement sta1=null;
         PreparedStatement sta2=null;
         try
         {
            sta1=con.createStatement();
         sta2=con.prepareStatement("SELECT * FROM NEWS WHERE ID=?");
         for(int i=0;i<IDS.size();i++)
            {
               try
                {
             int ID=IDS.get(i);
             out.print(ID);
             if(i!=0)
             sql+=" OR ID="+ID;
             else
             sql+=" ID="+ID;
             sta2.setInt(1,ID);
             ResultSet set=sta2.executeQuery();
             if(set.next())
             {
             out.print("true");
             }
              
               }
                 catch(Exception e)
                {
                       e.printStackTrace();
                }
                      j++;
               }     
            sta1.executeUpdate(sql);
            sta1.close();
            sta2.close();
            con.close();
           }
           catch(SQLException e)
           {
           e.printStackTrace();
           }
          }
        %>
结果只是 1 2 3 4 5 6
若去掉
sta1.executeUpdate(sql);
结果才是1true 2true 3true 4true 5true 6true
希望能人相助,在下感激不尽,立即给分100

解决方案 »

  1.   

    补充问题:我的表是
    CREATE TABLE NEWS (ID INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,title VARCHAR(100) NOT NULL,PRIMARY KEY(ID))
      

  2.   

    String [] value = request.getParameterValues("checkbox");//获得选中的id值,
    把它再转成个字符串,比如1,2,3 然后直接delete from table where id in 字符串
      

  3.   

    好象是mysql的问题,我重装系统后就正常了