John Topley's KnowledgebaseRetaining The Time Component When Writing To A Date ColumnSaturday, 15 May 2004Writing to a date type column in a database using the JDBC PreparedStatement's setDate method, results in the time component being lost i.e. it gets set to 00:00:00. The code given below shows how to retain the time component. In this example, “pstmt” is a variable of type java.sql.PreparedStatement and the current date and time are used. Note that java.util.Date's getTime method can be used when specific dates need to be passed to the setTimestamp method. pstmt.setTimestamp(1, new Timestamp(System.currentTimeMillis())); |
![]() |

