勾选的复选框数量不等于页面上显示的数量

时间:2018-06-25 07:18:09

标签: java mysql

我想选中此网页上的两个复选框以删除这些行。但是,当我按下删除按钮时,它显示“ 0条记录已删除”。此外,我检查的两行数据都没有删除。我该怎么做才能解决这个问题?

显示(勾选2个框):

enter image description here

点击删除按钮后显示的网页:

enter image description here

我的删除按钮的代码

    <%
    String[] ids = request.getParameterValues("userAction");
    int count=0;
    Connection conn = null;
    try {
        Class.forName("com.mysql.jdbc.Driver");
        // Step 2: Define Connection URL
        String connURL = "jdbc:mysql://localhost/medicloud?user=root&password=root";
        // Step 3: Establish connection to URL
        conn = DriverManager.getConnection(connURL);

        if (ids != null)
        {
        for(int i=0; i<ids.length; i++){

        String sqlStr = "DELETE from exercise1 && exercise2 WHERE id=?";
        PreparedStatement pstmt = conn.prepareStatement(sqlStr);
        pstmt.setInt(1, Integer.parseInt(ids[i]));
        //pstmt.setInt(1, Integer.parseInt(ids[i]));
        int rec=pstmt.executeUpdate();
        if (rec==1)
            count++;
        }
        }


            //System.out.println(functions);
%>
    <form action="exercise.jsp" method="post">
        <label><%=count%> record(s) deleted!!</label>
        <input type="submit" value="Return" name="ReturnBtn" />
    </form>
<%

        conn.close();
    } catch (Exception e) {
        out.println(e);
    }
%>

0 个答案:

没有答案