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 format error 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 format error" Watch "date format error" New topic
Author

date format error

Amar Deep Singh Chaudhary
Ranch Hand

Joined: Dec 26, 2006
Posts: 49
hi ranchers !
i have a confusion with the Date() method of the java.util package and the java.sql date() method.i have created a table with ms Access with a field data type as Date.what is the difference between these two Date method.which date format will not throw the Exception and which will be more accurate to this date format.plese someone answer to me.


"A thinking mind never dies"
Gaurav Chikara
Ranch Hand

Joined: Jun 09, 2000
Posts: 410
Java sql Date extends Java util Date
In other words it has more methods and provides more functionality
It is always better to use java.sql.Date to get enhanced functionality


SCJP,SCWCD,SCBCD<br />If Opportunity doesn't knock then build the door
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30138
    
150

Amar,
java.sql.Date is a subclass of java.util.Date. You need to use java.sql.Date when passing data to JDBC APIs for the code to compile.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Amar Deep Singh Chaudhary
Ranch Hand

Joined: Dec 26, 2006
Posts: 49
hi ranchers i want to get the current time and date by uding the java.sql.Date() method and insert this into the database.is anyone can give the code for this.thanks.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30138
    
150

Amar,
Try this:

// get current Date as java.util.Date
// convert to milliseconds
// create java.sql.Date for JDBC code
long currentTime = new java.util.Date().getTime();
java.sql.Date dateToInsert = new java.sql.Date(currentTime);
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: date format error
 
Similar Threads
Unable to get Date instance in a particular format
Validating The Date String
painful java.util.Date bug
Date Format: How to know the Date in which format
Another format check :P