Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Date

 
francis varkey
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1082
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic