I have a web page which allows the user to enter a word and when that word is submitted, it will be deleted from the mysql database. The problem however is that the statement is not being executed.
My form:
<form id="rem1" action="removeGER" method="GET">
<input type="text" name="wordToRemoveGER" placeholder="Entry (GER)">
<input type="submit" id="removeBtnGER" value="Remove Entry">
</form>
My servlet:
@WebServlet(name = "removeGER", urlPatterns = {"/removeGER"})
public class removeGER extends HttpServlet {
/**
* Handles the HTTP <code>POST</code> method.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
String wordGER = request.getParameter("wordToRemoveGER");
PrintWriter out = response.getWriter();
out.println("<!DOCTYPE html>");
out.println("<html>");
out.println("<head>");
out.println("<title>Remove Word</title>");
out.println("</head>");
out.println("<body>");
Connection conn = null;
try {
// Database Checking Area
SimpleDataSource.init("/database.properties");
} catch (ClassNotFoundException ex) {
Logger.getLogger(Register.class.getName()).log(Level.SEVERE, null, ex);
}
try {
conn = SimpleDataSource.getConnection();
Statement stat = conn.createStatement();
//ResultSet result =
stat.executeQuery(" DELETE FROM `word` WHERE `word` = \""+wordGER+"\"");
out.println("<h2>You have successfully removed the word " + wordGER + "!</h2>");
} catch (SQLException ex) {
Logger.getLogger(removeID.class.getName()).log(Level.SEVERE, null, ex);
}
out.println("</body>");
out.println("</html>");
}
}
I know that the String is correctly being retrieved from the form, and I know that the try block is being executed. The problem seems to be with the mysql statement itself.
executeQuery()-command. You have two (SETandDELETEcommand).