Datetime in java
java, jdbc
Solution
1) Use `java.util.Date` in your java class.
2) Set datatye `TIMESTAMP` in mysql.
Date CreatedDate= new Date(System.currentTimeMillis());
For PreparedStatement: It may be like this:
PreparedStatement PStmt = con.prepareStatement(Sql query);
PStmt.setDate(1,CreatedDate);
Problem
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); ```