怎么实现多删除呀,55555555要开始了,不会批量删除55555555

解决方案 »

  1.   

    获取要删除的ids,然后遍历删除
      

  2.   

    con.setAutoCommit(false);
    pstmt = con.prepareStatement(“delete from tab1 where id=?”);
    for(int i=1;i<5;i++){
    pstmt .setInt(1,i);
    pstmt.addBatch();
    }
    pstmt.executeBatch();
    con.commit();
      

  3.   

    public int delete(String[] id)
    {
    String ids = "";
    for (int i = 0; i < id.length; i++)
    {
    ids += id[i];
    if(i<id.length-1)
    {
        ids+=",";
    }
    }
    String sql = "delete from table where id in ("+ids+")";}delete.jsp页面
    String id[] = request.getParameterValues("addressId");
      

  4.   

    public int delete(String[] id)
    {
    String ids = "";
    for (int i = 0; i < id.length; i++)
    {
    ids += id[i];
    if(i<id.length-1)
    {
        ids+=",";
    }
    }
    String sql = "delete from table where id in ("+ids+")";}delete.jsp页面
    String id[] = request.getParameterValues("addressId");
      

  5.   


    支持,不过,生成ids后应该有这么一句:
    ids = ids.substring(0, ids.length-1);否则,组装的sql是错误的。
      

  6.   

    java技术群:69705156
    欢迎加入
      

  7.   

    public int delUser(int[] userId) {
    int re = 0;
    String sql = null;
    try {
    //循环  进行删除操作
    for (int i = 0; i < userId.length; i++) {
    conn = this.getConn();
    sql = "delete from userInfo where userID = " + userId[i];
    ps = conn.prepareStatement(sql);
    re = ps.executeUpdate();
    }

    } catch (ClassNotFoundException e) {
    e.printStackTrace();
    } catch (SQLException e) {
    e.printStackTrace();
    } return re; 
      

  8.   

    这贴也能出名
    sql问题
    用in
      

  9.   

    sql 里的批量删除语句
    delete * from 表名 where 条件1 or 条件2 or 条件3
      

  10.   

    executeBatch 批量执行sql语句
    不过....小弟一直都是这么删除的 delete from [table] where id in(id1,id2,di3....)...表鄙视我
      

  11.   

    那个 我想问下啊 在Hibernate 怎么根据条件删除呢? 而不是一条一条删除如果一定要一条条删除的话 那我想问下 是根据某些条件同时删除一些数据快呢? 还是把要删除的数据查询出来一条条进行删除快呢? 期待有人回答我...
      

  12.   

    页面获取你要删除信息的ID,然后传参给数据库,用存储过程删除,页面load删除后的列表,就可以了
      

  13.   

    像mysql数据库里面就自带一个批量删除的功能,可以试试,我们当时给一个学校做个毕业生信息管理系统的时候就是这样处理的,试试
      

  14.   

    最好的方法是用事务批量处理,也可以用循环把删除的编号写在一条Delete语句后面,就像下面一样处理:
    public int delete(String[] id) 

    String ids = ""; 
    for (int i = 0; i < id.length; i++) 

    ids += id[i]; 
    if(i <id.length-1) 

        ids+=","; 


    String sql = "delete from table where id in ("+ids+")"; } delete.jsp页面 
    String id[] = request.getParameterValues("addressId"); 
      

  15.   

    try{
        con.setAutoCommit(true);
    }catch(Exception e){
      try{
        //事务回滚
        con.rollback();
      }catch(Exception e1){
        e1.printStackTrace();
      }
      e.printStackTrace();
    }
      

  16.   

    用数组接收要删除的记录id,然后用个循环调用sql的删除语句就行了 
      

  17.   

     
    public int delete(String[] id) 

    String ids = ""; 
    for (int i = 0; i < id.length; i++) 

    ids += id[i]; 
    if(i <id.length-1) 

        ids+=","; 


    String sql = "delete from table where id in ("+ids+")"; } delete.jsp页面 
    String id[] = request.getParameterValues("addressId"); 
     
      

  18.   

    利用循环语句进行删除啊,至于是FOR 还是 WHILE就看你个人喜欢了