title: deleting data from database with jsp page
body: <p>I am writing an online reservation system. I have problem with my code where the user can cancel their reservations with cancel button on jsp page. But my code is not working. It cannot delete data from database. How can I do that? <a href="https://i.stack.imgur.com/RGtqY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RGtqY.png" alt="Image of my page"></a></p>
  
  <p>myreservations.jsp</p>
  
  <pre><code> &lt;%@page contentType="text/html" pageEncoding="UTF-8"%&gt;
   &lt;%@ page import ="java.sql.*" %&gt;
   &lt;!DOCTYPE html&gt;
   &lt;html&gt;
   &lt;head&gt;
      &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
   &lt;title&gt;Book Ticket&lt;/title&gt;
   &lt;/head&gt;
  
   &lt;body background="http://www.teamarking.com/barcode/bar_background.jpg"&gt; 
   &lt;form method="post" action="reservations.jsp"&gt;
  
  
      &lt;center&gt;    
  
          &lt;table border="1" width="30%" height="30%"&gt;
              &lt;tr&gt;
                  &lt;th&gt;&lt;font color='#D18603'&gt;ActivityID&lt;/font&gt;&lt;/th&gt;
                  &lt;th&gt;&lt;font color='#D18603'&gt;Username&lt;/font&gt;&lt;/th&gt;                  
                  &lt;th&gt;&lt;font color='#D18603'&gt;Ticket&lt;/font&gt;&lt;/th&gt;
                  &lt;th&gt;&lt;font color='#D18603'&gt;Cancel&lt;/font&gt;&lt;/th&gt;
              &lt;/tr&gt;
  
  
  
  
              &lt;%
                  Class.forName("org.apache.derby.jdbc.ClientDriver").newInstance();
                  Connection con = DriverManager.getConnection("jdbc:derby://localhost:1527/users", "users", "123");
                  String username = (String) request.getSession().getAttribute("username");
                  Statement st = con.createStatement();
                  ResultSet rs;
                  rs = st.executeQuery("select * from reservation where username='" + username + "'");
                  while (rs.next()) {
  
                      String activityid = rs.getString("id");
                      username = rs.getString("username");
                      String buy = rs.getString("buy");
  
                      out.println("&lt;tr&gt;");
                      out.println("&lt;td&gt;" + activityid + "&lt;/td&gt;");
                      out.println("&lt;td&gt;" + username + "&lt;/td&gt;");
                      out.println("&lt;td&gt;" + buy + "&lt;/td&gt;");
                      out.println("&lt;td&gt;&lt;b&gt;&lt;form action='cancel.jsp'&gt;&lt;input type='submit' name='cancel' value='Cancel Reservation'&gt;&lt;/form&gt;&lt;/b&gt;");
  
                      out.println("&lt;/tr&gt;");
  
                  }
  
                  st.close();
  
              %&gt;
  
      &lt;/center&gt;
      &lt;/table&gt;
  
  
      &lt;br&gt;&lt;a href='success.jsp'&gt;Back&lt;/a&gt;
  
      &lt;br&gt;&lt;br&gt;&lt;a href='logout.jsp'&gt;Log out&lt;/a&gt;
  
  
      &lt;/form&gt;
     &lt;/body&gt;
     &lt;/html&gt;
  </code></pre>
  
  <p>cancel.jsp</p>
  
  <pre><code> &lt;%@page contentType="text/html" pageEncoding="UTF-8"%&gt;
   &lt;%@ page import ="java.sql.*" %&gt;
   &lt;%
  
  String AcivityID = request.getParameter("ActivityID");
  String Username = request.getParameter("Username");
  String Ticket = request.getParameter("Ticket");
  
  Class.forName("org.apache.derby.jdbc.ClientDriver").newInstance();
  Connection con = DriverManager.getConnection("jdbc:derby://localhost:1527/users", "users", "123");
  
  String sorgu = "delete from reservation where id='" + request.getParameter(AcivityID) + "'AND username='" + request.getParameter(Username) + "'AND buy='" + request.getParameter(Ticket) + "'";
  
  java.sql.Statement st = con.createStatement();
  
  int rowNum = st.executeUpdate(sorgu);
  response.sendRedirect("cancelled.jsp");
  st.close();
  %&gt;
  </code></pre>