title: How to insert current time in MySQL using Java
body: <p>I need to insert the current date and time (milliseconds) into MySQL. I did the following:</p>
  
  <pre><code>long time = System.currentTimeMillis();
  java.sql.Timestamp timestamp = new java.sql.Timestamp(time);
  System.out.println("Time in milliseconds :" + timestamp);
  </code></pre>
  
  <p>And I got the time in milliseconds correctly (e.g. 2013-03-21 00:08:33.523). However, I need to insert this information into MySQL database. I tried the following using <code>PreparedStatement</code></p>
  
  <pre><code>prepStmt.setTimestamp(2,timestamp);
  </code></pre>
  
  <p>But the time is inserted without milliseconds (e.g. 2013-03-21 00:08:33).</p>
  
  <p>How can I insert the time with milliseconds. </p>
  
  <p><strong>EDIT:</strong> The column in the database is of <code>DATETIME</code> type.</p>