File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Date