Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Date" Watch "Date" New topic
Author

Date

francis varkey
Ranch Hand

Joined: Sep 13, 2005
Posts: 166
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
 
Similar Threads
Date() object when using javascript
Problems in accessing the Date Field
How to grab current date
is that any utility class that help compare date within start and end date ?
Why The LOGO and My name are upside down