Delete the Entry from the list

26 views Asked by At

I have succeed in listing entries from the db but I want to the delete the entry with the help of checkbox. So when someone check the check box that particular entry should be deleted.

I have written the code for it with the help of reference but my Vehicle id is in Integer and I am writing in the code in string but when I try to convert into Interger.parseInt then its not working.

Here is my code:

Listing.Jsp

<TR>
<th>Vehicle ID </th>
<th> EzTagCode </th>
<th> Vehicle Type </th>
<th> Plate No </th>
<th> Model Name </th>
<th> Color </th>
</TR>
<TR>
<%
int i=0; while (rs.next()) {
%>
>
<%--<td><input type="checkbox" name="check<%=i%>" --%>
<TD><%=rs.getInt(1)%></TD>
<TD><%=rs.getString(3)%></TD>
<TD><%=rs.getString(4)%></TD>
<TD><%=rs.getString(5)%></TD>
<TD><%=rs.getString(6)%></TD>
<TD><%=rs.getString(7)%></TD>
</TR><%
i++;
%>
<% } %>
<%
// close all the connections.
rs.close();
st.close();
conn.close();
} catch (Exception ex) {
%>
</font>
<font size="+3" color="red"></b>
<%
out.println("Unable to connect to database.");
}
%>
</TABLE>
<input type="submit">

Delete.jsp

<%String id[]= new String[10];
for(int i=0;i<10;i++){
id[i]=request.getParameter("check"+i);
int b = Integer.parseInt(id[i]);
out.println(id[i]);

%>
<%
try {

st=conn.createStatement();
for(int a=0;a<10;a++){
out.println("hello");
String QueryString = "delete from Vehicle where VehicleID='"+id[a]+"'";
rs = st.executeQuery(QueryString);
1

There are 1 answers

0
Karan shah On

here check in request.getParameter("check"+i) is not an int value that's why you output is not generated.

id[i]=request.getParameter("check"+i);
int b = Integer.parseInt(id[i]);