checkbo选择多个删除

来源:互联网 发布:罗俊 中山大学 知乎 编辑:程序博客网 时间:2024/06/15 07:17

 
 1:servlet调用:
 String[] len=request.getParameterValues("check");
  for(int i=0;i<len.length;i++)
  {
   Product sio=new Product();
   ProductsService psi=new ProductsServiceImpl();
   psi.deleteProducts(len);
  }
 2.方法:public void deleteProducts(String[] productID)
 {
   String sql=null;
   Product pd=null;
   Connection conn = null;
   DBConnection db = null;
   try {
   db=new MSSQLConnection();
   conn=db.getConnection();
      Statement stmt=conn.createStatement();
      StringBuffer sbSql = new StringBuffer();
      for(int i=0;i<productID.length;i++)
      { 
      sbSql.append("'") .append(productID[i]) .append("',");
      sql="delete from product where productID in (" + sbSql.substring(0, sbSql.length() - 1) + ")";
      int  rst=stmt.executeUpdate(sql);
      }
  } catch (Exception e) {
    e.printStackTrace(); 
  }
  finally
  {
   conn=null;
   db.close();
  }
 }

原创粉丝点击