Reputation: 49
For log entry of a web application I have table with primary key DATETIME
in MySQL table.
But java.util.Date
is in different format causing mapping error in Hibernate.
How can I map DATETIME
type of MySQL table to java.util.Date
?
Upvotes: 1
Views: 3201
Reputation: 4348
try this...
java.sql.Timestamp oracleDate = new java.sql.Timestamp(yourdate.getTime());
edit...
I just checked what I was doing in some of my code, and java.util.Date is working with no specific settings for hibernate. My code above probably only helps JDBC code. You might have a different type of problem. Can you share some code?
Upvotes: 2
Reputation: 34677
If you're using hibernate, use a @Temporal annotation with TemporalType.DATE and Hibernate should handle things for you. If not, leave a comment.
Upvotes: 0
Reputation: 703
java.util.Date temp = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSSSSS").parse("2014-01-24 11:23:00.000000");
I Think this is what you are looking for?
The code is
public class Test {
public static void main(String[] args) throws ParseException {
java.util.Date temp = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSSSSS")
.parse("2014-01-24 11:23:00.000000");
System.out.println(temp);
}}
Now pass this to your database
Upvotes: 1