title: How to store date from datepicker into mysql database?
body: <p>I have tried storing date from input to mysql database, but the value is still null. Is there anyway to make it work? Also it says 'data added' but it is not inserted in database and below it in console it gives NullPointerException.</p>
  
  <p><strong>JSP page</strong></p>
  
  <pre><code>&lt;html&gt;
      &lt;link rel="stylesheet" href="http://code.jquery.com/ui/1.10.2/themes/smoothness/jquery-ui.css" /&gt;
      &lt;script src="http://code.jquery.com/jquery-1.9.1.js"&gt;&lt;/script&gt;
      &lt;script src="http://code.jquery.com/ui/1.10.2/jquery-ui.js"&gt;&lt;/script&gt;
  &lt;head&gt;
      &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
  &lt;title&gt;Date Input&lt;/title&gt;
  &lt;script&gt;
      $(function(){
          $('.datepicker').datepicker();
      });
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;form action="Date" method="post"&gt;
          &lt;div class="row"&gt;
          Date: &lt;input class="datepicker" type="text" name="date" id="date"&gt;
          &lt;/div&gt;
          &lt;input type="submit" value="save"&gt;
      &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>Java class for connection</strong></p>
  
  <pre><code>package com.jsppractise;
  public class Date extends HttpServlet {
  
      private static final long serialVersionUID = 1L;
  
      protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
          try {
              response.setContentType("text/html");
              PrintWriter out = response.getWriter();
              String dt = request.getParameter("date").toString();
  
              Class.forName("com.mysql.jdbc.Driver");
              Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/sportsevent", "root", "root");
  
              PreparedStatement ps = con.prepareStatement("insert into date (date) values(?)");
              java.util.Date date = new SimpleDateFormat("MM/dd/yyyy").parse(dt);
              java.sql.Date d = new java.sql.Date(date.getTime());
              ps.setDate(1, d);
              ps = con.prepareStatement("select * from date");
              ResultSet s;
              s = ps.executeQuery();
              if (s != null) {
                  System.out.println("date added");
              } else {
                  System.out.println("not added");
              }
  
              out.print("&lt;html&gt;&lt;body&gt;&lt;table&gt;&lt;th&gt;Date&lt;/th&gt;");
              out.print("&lt;tr&gt;&lt;td&gt;" + s.getDate(1) + "&lt;/td&gt;&lt;/tr&gt;");
              out.print("&lt;/table&gt;&lt;/body&gt;&lt;/html&gt;");
          } catch (Exception e) {
              System.out.println(e);
          }
      }
  }
  </code></pre>