title: Insert date into database using Prepared Statement
body: <p>I want to insert a date of the format YYYY-MM-DD which is entered by the user into the database using Prepared Statement in JSP by this way:</p>
  
  <pre><code> SimpleDateFormat reFormat = new SimpleDateFormat("YYYY-MM-DD") 
   Date activityDate = reFormat.parse(request.getParameter("activity_date"));
   java.sql.Date sqlDate = new java.sql.Date(activityDate.getTime());
  
   String query = "INSERT INTO schedule(login_name,activity_date) VALUES (?, ?)";
   PreparedStatement stmt = connection.prepareStatement(query);
   stmt.setString(1,request.getParameter("name_of_user"));
   stmt.setDate(2,sqlDate);
   stmt.executeUpdate();
  </code></pre>
  
  <p>however, if the user enter for example: 2012-06-22  in the database a wrong date 2012-01-01 is saved instead of 2012-06-22</p>
  
  <p>Is anyone know what is the problem ??</p>