Although an old post, the answer is simple and depends on your requirement - according to your requirements, use the DATETIME data type and use the following
java.util.Date date = new Date(); pst.setTimestamp(columIndex, new java.sql.Timestamp(date.getTime()).getTime());
See the discussion from both the database and the jdbc side.
Start with the data type in the database and select the appropriate one. The one that exactly suits your case is DATETIME, as you want the date and hour / min / sec. The DATETIME type is used to store the time of a wall clock, while TIMESTAMP is used for a fixed point in time (several milliseconds after an era). There is also a difference in how they are stored inside MySQL.
Now that you are on the JDBC side, you have the API methods for Date (date only), Timestamp (date and time) and Time (time only). That is all JDBC has to offer. So the API that suits you is setTimestamp
Shailendra
source share