title: Spring MVC - delete record from JSP table
body: <p>I got table in JSP, which is table's mirror image from database (all records and columns are displayed), and next to each row I got button "delete" which deletes row from database by ID. But when I click "delete" button then nothing happens in database, it seems like selected row's ID is null, but at address bar selected ID is displayed. What am I doing wrong?</p>
  
  <p>Controller:</p>
  
  <pre><code>@RequestMapping(value="/checkout.html", method = RequestMethod.POST)
  public ModelAndView checkOut(Model model, @RequestParam(value = "id", required = false) String id) throws SQLException{
  
      setAppContext();
  
      clinicService.deletePatient(id);
  
      List&lt;Patient&gt; patients = clinicService.getAllpatients();    
      model.addAttribute("patients", patients);
  
      ModelAndView checkout = new ModelAndView("CheckOut");
      return checkout;
  
  }
  </code></pre>
  
  <p>DAO:</p>
  
  <pre><code>public void deletePatient(String id) throws SQLException {
      String query = "delete FROM virtualclinic.patient WHERE idpatient=?";
      Connection con = null;
      PreparedStatement ps = null;
  
          con = dataSource.getConnection();
          ps = con.prepareStatement(query);
          ps.setString(1, id);
          int out = ps.executeUpdate();
  
  }
  </code></pre>
  
  <p>Service:</p>
  
  <pre><code>public void deletePatient(String id) throws SQLException {
      ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("clinicconfig.xml");
      patientDAO = ctx.getBean("patientDAO", PatientDAOImpl.class);
  
      patientDAO.deletePatient(id);
  }
  </code></pre>
  
  <p>JSP file:</p>
  
  <pre><code>&lt;c:forEach items="${patients}" var="patient"&gt;
              &lt;tr style="font-size: 10"&gt;
                  &lt;td&gt;${patient.id}&lt;/td&gt;
                  &lt;td&gt;${patient.name}&lt;/td&gt;
                  &lt;td&gt;${patient.lastName}&lt;/td&gt;
                  &lt;td&gt;${patient.gender}&lt;/td&gt;
                  &lt;td&gt;${patient.age}&lt;/td&gt;
                  &lt;td&gt;${patient.phoneNumber}&lt;/td&gt;
                  &lt;td&gt;${patient.address}&lt;/td&gt;
                  &lt;td&gt;${patient.disease}&lt;/td&gt;
                  &lt;td&gt;${patient.condition}&lt;/td&gt;
                  &lt;td&gt;${patient.roomType}&lt;/td&gt;
                  &lt;td&gt;${patient.roomNumber}&lt;/td&gt;
                  &lt;td&gt;${patient.date}&lt;/td&gt;
                  &lt;td&gt;&lt;form action="/VirtualClinic/checkout.html?selectedPatient=${patient.id}"  method="post"&gt;&lt;input type="submit" value="Delete"/&gt;&lt;/form&gt;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;/c:forEach&gt;
  </code></pre>
  
  <p>Error(?):</p>
  
  <pre><code>INFO: Mapped "{[/checkout.html],methods=[GET]}" onto public   org.springframework.web.servlet.ModelAndView  org.damian.controller.CheckOutController.infoPatient(org.springframework.ui.M    odel) throws java.sql.SQLException
  lut 17, 2016 3:16:57 AM org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMa    pping register
  INFO: Mapped "{[/checkoutPatient.html],methods=[GET]}" onto public org.springframework.web.servlet.ModelAndView org.damian.controller.CheckOutController.checkOut(org.springframework.ui.Model,java.lang.String) throws java.sql.SQLException
  </code></pre>