I have a jsp page that displays records in a dynamic table with each record
having its own checkbox called select. When a check box is selected and the
form is submitted it goes to another page called delete.jsp which is shown
below. The code works but at the moment it will only delete one record. I would
like to be able to be able to use delete to remove all the checked items I
have selected but I cannot seem to get it to delete more than one record at a time.
I tested the page and printed out the string called selected and it printed the
string "1,2,3" which are the ID values that i selected. Does anyone have any
ideas where i am going wrong or maybe you know a better way that i could
delete more than one at a time.
<%
String deleteArray[] = request.getParameterValues("select");
String selected="";
if (deleteArray != null) {
// multiple items selected
for (int i = 0; i < deleteArray.length; i++) {
selected += deleteArray[i];
if( i < deleteArray.length -1) {
selected += ",";
}
}
}
Driver DriverdeleteTopics = (Driver)Class.forName(MM_connQuestion_DRIVER).newInstance();
Connection ConndeleteTopics = DriverManager.getConnection(MM_connQuestion_STRING,MM_connQuestion_USERNAME,MM_connQuestion_PASSWORD);
PreparedStatement deleteTopics = ConndeleteTopics.prepareStatement("DELETE FROM Question.topic WHERE Topic_ID IN ('" + selected + "')");
deleteTopics.executeUpdate();
%>
Any help would be much appreciated
Thanks