当前位置: 首页 > 工具软件 > checkBo > 使用案例 >

checkbo选择多个删除

范浩荡
2023-12-01

 
 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();
  }
 }

 类似资料: