爱问知识人 爱问教育 医院库

JSP多选删除,详细代码或者下面错误指出

首页

JSP多选删除,详细代码或者下面错误指出

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" contentType="text/html; charset=gb2312"%>
<%
 tCharacterEncoding("gbk");
    // 接收复选框sampleid传过来的数组
  String   sampleidAll = "";
    String[] sampleid =  tParameterValues("sampleid") ;
 try{  
  for(int i=0;i <sampleid.length;i++)  
       {  
         sampleidAll+=sampleid[i];  
       }  
     }  
    catch(Exception e)  
   {}  

  Connection conn=null; 
    Statement stat=null;
    String driverName=" sql.jdbc.Driver"; 
    String userName="root"; 
    String userPasswd="12345"; 
    String dbName="dbtest"; 
    String tableName="test1";
    String url="jdbc:mysql://localhost:3306/"+ dbName;
    int row=0;
    String sql="delete from test1 where id="+sampleidAll;
     rName(driverName);
    conn= tConnection(url,userName,userPasswd);     
    stat= eateStatement(); 
    row=stat.executeUpdate(sql); 
  intln(sql);
    if(row!=0)
    {
      ndRedirect("index.jsp"); 
    }
    else{
     ndRedirect("success.jsp"); 
    }

     ose();
    %>

 <!--        tHeader("refresh", "2;URL=index.jsp") ;
        if (flag) {
%>
            数据删除成功,两秒后跳转到数据管理列表页! <br>
            如果没有跳转,请按<a href="index.jsp">这里</a>!
<%
        } else {
%>
            数据删除失败,两秒后跳转到数据管理列表页!<br>
            如果没有跳转,请按<a href="index.jsp">这里</a>!
<%
        }
%>-->
  </body>
</html>

<%@ pag……
提交回答
好评回答
  • 2012-09-17 13:19:56
    你的代码没有问题,关键问题是你不很了解sql语法
    要删除多个记录,必须使用循环删除的方法或者sql的or条件,下面给你的是每一次删除一条记录的循环删除的方法:
    String sql="delete from test1 where id=?";
    stat= eatePreparedStatement(sql);
    PreparedStatement stmt = null;
    stmt =  epareStatement(sql);
    for (int i = 0; i < sampleid.length; i++) {
              tInt(1,  rseInt(sampleid[i]));
             iCount += stmt.executeUpdate();
    }
    建议你好好学习一下数据库的知识,学好开发,不懂数据库的知识是不行的

    好***

    2012-09-17 13:19:56

其他答案

类似问题

换一换
  • 其他编程语言 相关知识

  • 电脑网络技术
  • 电脑网络

相关推荐

正在加载...
最新资料 推荐信息 热门专题 热点推荐
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200

热点检索

  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 173-192
返回
顶部
帮助 意见
反馈

确定举报此问题

举报原因(必选):