How to insert current time in MySQL using Java

AaronHatton

New Member
I need to insert the current date and time (milliseconds) into MySQL. I did the following:\[code\]long time = System.currentTimeMillis();java.sql.Timestamp timestamp = new java.sql.Timestamp(time);System.out.println("Time in milliseconds :" + timestamp);\[/code\]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\]\[code\]prepStmt.setTimestamp(2,timestamp);\[/code\]But the time is inserted without milliseconds (e.g. 2013-03-21 00:08:33).How can I insert the time with milliseconds. EDIT: The column in the database is of \[code\]DATETIME\[/code\] type.
 
Back
Top