Java sql - How to insert TimeStamp into a mysql database including milliseconds
<p>How do I convert a Java TimeStamp object to a SQL datetime type that includes milliseconds?
When I insert my TimeStamp obj into the database the milliseconds are gone.</p>

<p>This is my Java source code to translate a String into a Timestamp object:</p>

<pre><code>import java.sql.Timestamp;
...
...
String timeStr = "2013-08-30 19:11:49.113";
Timestamp timeCreated = Timestamp.valueOf(timeStr);
timeCreated.toString(); //returns "2013-08-30 19:11:49.113"
</code></pre>

<p>My table dfinition in SQL:</p>

<pre><code>CREATE TABLE `Event` (EventTimeStamp datetime NOT NULL);
</code></pre>

<p>This is how I insert the TimeStamp object into my Database:</p>

<pre><code>PreparedStatement psInsert;
Connection conn = ...
psInsert = conn
            .prepareStatement("INSERT INTO `Event` (EventTimeStamp) VALUES(?)");  

psInsert.setTimestamp(1, timeCreated);
psInsert.executeUpdate();
</code></pre>

<p>After insertion the TimeStamp is cut and there are no milliseconds anymore:</p>

<pre><code>2013-08-30 19:11:49
</code></pre>

<p>Thx</p>