jeudi 28 juin 2018

Checkbox count in JSP

I have an error when it comes to checkbox count. I have a checkbox appear next to my data. For example, I ticked 2 checkboxes, and I press delete. It will always appear my count as 0. How do I fix this error ? I have tried several ways to fix this but my count will always display as 0.

This is a picture of the message display

 String[] id = request.getParameterValues("deletechkbox");
        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 (id != null)
            {

        for(int i=0; i<id.length; i++){

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




Aucun commentaire:

Enregistrer un commentaire