I have a JDBC current date and time insert into Mysql Database.
It submits the current date and a fixed time into the Mysql date type field as 2012/05/25 00:00:00. The date part works very fine but the time doesn’t shows any value.
I’m inserting the value with the following code:
java.util.Date myDate = new java.util.Date();
java.sql.Date sqlDate = new java.sql.Date(myDate.getTime());
PreparedStatement PStmt = con.prepareStatement(Sql query);
PStmt.setDate(1,sqlDate);
1) Use
java.util.Datein your java class.2) Set datatye
TIMESTAMPin mysql.For PreparedStatement: It may be like this: