This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes JDBC and the fly likes Date Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Date" Watch "Date" New topic
Author

Date

francis varkey
Ranch Hand

Joined: Sep 13, 2005
Posts: 169
Respected Sirs,

What is the correct way for inserting date values in database using java ?. What is the difference between java.util.Date and java.sql.Date?.


Regards,
Francis
Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1081

Originally posted by francis varkey:
What is the correct way for inserting date values in database using java ?.


If you have a java.util.Date date and you want to save it in database with time then below is the correct way

TimeStamp timestamp = new TimeStamp(date.getTime());
statement.setTimeStamp(timestamp );





What is the difference between java.util.Date and java.sql.Date?.




sql.Date extend java.util.Date, it is the thin wrappers around a numeric value representing a point in time. The SQl Date class ignore the information regarding the time of day .

Shailesh


Gravitation cannot be held responsible for people falling in love ~ Albert Einstein
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Date