I want to insert the current date and time into a columns defined as datetime type.
I typed the following code:
java.sql.Date sqlDate = new java.sql.Date(new java.util.Date().getTime());
PrepStmt.setDate(1, sqlDate);
When I check the database, I find that the date inserted correctly, but the time is: 00:00:00. What is the fix ?
Since you are using
datetimeas your column type, you need to usejava.sql.Timestampto store your date, andPrepareStatement.setTimestampto insert it.Try using this: –