File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes java.util.Date and java.sql.Date problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "java.util.Date and java.sql.Date problem" Watch "java.util.Date and java.sql.Date problem" New topic

java.util.Date and java.sql.Date problem

tun zaw

Joined: Jan 23, 2008
Posts: 22

i use mysql database.User's date of birth is caught by java.util.Date in backing bean.while insert into database,mysql cannot accept.Cannot insert into table.Query not ok.if use java.sql.Date,also same result.
I have known sql.Date into mm/dd/ is little long.
if i use now() function in mysql,i can display like mm/dd/yyyy while i retrieve the date.
that is why?
Please help me.
Darryl Nortje
Ranch Hand

Joined: Jun 11, 2002
Posts: 140
Howzit Tun,

This is not a JSF question. So I assume someone is going to move this post. But I'll see if I can help anyway.

You want to convert from java.util.Date to a java.sql.Date. Is that correct?

have you try instantiating a java.sql.Date with the constructor that accepts a long as a parameter, and you get that long from java.util.Date.getTime()?
java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime());
tun zaw

Joined: Jan 23, 2008
Posts: 22
thanks for your answer.
thank you very much.
I agree. Here's the link:
subject: java.util.Date and java.sql.Date problem
It's not a secret anymore!