title: how to delete data from db using id - generated_key
body: <p>Please help me to resolve the same problem: I do not know how to delete data from table by id that is auto generated in mysql, I think that this problem can be resolved using GENERATED_KEY in JBDC, all in all I do not know, help me with info how to delete by table id.</p>
  
  <p>table 'note':</p>
  
  <pre><code>CREATE TABLE `note` (
  `id` MEDIUMINT NOT NULL AUTO_INCREMENT,
  `noteName` VARCHAR(100) NOT NULL ,
  `note` VARCHAR(1000) NOT NULL ,
   PRIMARY KEY (`id`)
  ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
  </code></pre>
  
  <p>Here I am getting value now it is - 'noteName' but it is incorrect I need to get id for every row in a table</p>
  
  <pre><code>Statement st = con.createStatement();
  ResultSet rs;
  ResultSet resultSet;
  rs = st.executeQuery("SELECT * FROM note");
  while (rs.next()) { 
  %&gt;
      &lt;tr&gt;
          &lt;td&gt;&lt;input type="checkbox"&gt;&lt;/td&gt;
          &lt;td id="noteName"&gt;&lt;%=rs.getString(1) %&gt;&lt;/td&gt;
          &lt;td&gt;&lt;%=rs.getString(2) %&gt;&lt;/td&gt;
          &lt;td&gt;time&lt;/td&gt;
          &lt;td id="close"&gt;
              &lt;a href=deleteData?id=&lt;%=rs.getString(1) %&gt;&gt;&lt;button onclick="deleteRow()" type="button" class="close" data-dismiss="modal"&gt;&amp;times;&lt;/button&gt;&lt;/a&gt;
          &lt;/td&gt;
      &lt;/tr&gt;
  &lt;% }
      rs.close();
      st.close();
      con.close();
  %&gt;
  </code></pre>
  
  <p>Here I am deleting data:</p>
  
  <pre><code>public class deleteData extends HttpServlet {
  
  protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
          int value = Integer.parseInt(request.getParameter("id"));
      try {
          Class.forName("com.mysql.jdbc.Driver");
          Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/evernoteDB",
                  "evernoteDB", "0633739768z");
  
          String query = "DELETE FROM note WHERE noteName = ?";
          PreparedStatement statement = conn.prepareStatement(query, Statement.RETURN_GENERATED_KEYS);
          statement.setInt(1, value);
          statement.executeUpdate();
  
          response.sendRedirect("/userNotes.jsp");
  
          conn.close();
      } catch (Exception e) {
          e.printStackTrace();
      }
  }
  }
  </code></pre>