Why my Update part can work but Delete button part cannot work . It gives an null pointer error.
——- 1st page here —–
out.print("<td>" + "<input name=update type=submit value=Update>" + " </td>");
out.print("<td>" + "<input name=delete type=submit value=Delete>" + " </td>
——- 2nd page here —–
String updButton = request.getParameter("update");
String delButton = request.getParameter("delete");
Statement stmt1 = con.createStatement();
Statement stmt2 = con.createStatement();
if (delButton.equals("Delete"))
{
String updStmt2 = "Delete from basket where (basketID="+strRowID+")";
stmt2.executeUpdate(updStmt2);
response.sendRedirect("ShowBasket.jsp");
}
if (updButton.equals("Update"))
{
String updStmt1 = "Update basket Set orderQty= "+strQty+" where (basketID="+strRowID+")";
stmt1.executeUpdate(updStmt1);
response.sendRedirect("ShowBasket.jsp");
}
%>
The quantity text field will be updated using update button and the delete button will delete the whole row.
Hi danrad,
It seems like both won’t work. You are saying that Update is working, Have you checked the DB after update operation, whether the value is changed or not ?
Also In the 1st page you are using Submit Buttons for
updating and what value is updated (It must be some textfield or an input type which can accept something from user)?
Can you update the question giving a clear picture of the problem that you have ? If so one can get easily what your problem is ? Now it seems like we need to guess the problem ?
ok Danrad,
Now , how the strRowID is initialized, that can be a problem ?
Also you have used two statements, why ?
A single statement is enough as user can’t press both buttons
same time.
Also Have you checked the connection is established or not with the DB?
regards
Anand