Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

date format error

 
Amar Deep Singh Chaudhary
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Gaurav Chikara
Ranch Hand
Posts: 412
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34095
337
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Amar Deep Singh Chaudhary
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author & internet detective
Marshal
Posts: 34095
337
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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);
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic