title: How to store java Calendar time in MySql timestamp?
body: <p>I was implementing Java "Forgot password functionality" and needed to add an expiring time to the reset password page. I created a Calendar class object for time and added 30 minutes to it. Code below:</p>
  
  <pre><code>java.util.Date utilDate = new java.util.Date();
  Calendar cal = Calendar.getInstance();
  cal.setTime(utilDate);
  cal.add(Calendar.MINUTE, 30);
  </code></pre>
  
  <p>And used in DB query as:</p>
  
  <pre><code>String query = "INSERT INTO forgotpasskeytab (keyId, emailid, expireIn) VALUES ('"+uniqueID+"','"+emailid+"','"+cal.getTime()+"')";
  </code></pre>
  
  <p>the <strong>expireIn</strong> column in my <code>forgotpasskeytab</code> table is of type <code>timestamp</code>.</p>
  
  <p>I am getting the following error while running:</p>
  
  <blockquote>
    <p>com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect datetime value: 'Fri Oct 09 20:39:14 IST 2015' for column 'expireIn' at row 1</p>
  </blockquote>
  
  <p>Is there any other better way to save expiring time in mysql DB table?</p>