I used the following code, but the DateTime field in SQL is represented as:
2005-04-08 00:00:00
I want to have the time too. what should I change?
Here is my code below:
// Get the system date and time.
java.util.Date utilDate = new Date();
// Convert it to java.sql.Date
java.sql.Date date = new java.sql.Date(utilDate.getTime());
...
...
...
PreparedStatement stmt = connection.prepareStatement(sql);
stmt.setDate(1, date);
Try using setTimestamp instead of setDate, since a timestamp is the prefered format for data and time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With