What is the difference Between java.util.Date and java.sql.Date in Java ?

By | August 10, 2019

In this post we will discuss What is the difference Between java.util.Date and java.sql.Date in Java ?

  1. As per Java documentation java.sql.Date is a wrapper around millisecond value which is used by JDBC to identify an SQL DATE type.
  2. java.sql.Date just represent DATE information without time information while java.util.Date represent both Date and Time information . This is the main differences why java.util.Date cannot directly map to java.sql.Date.
  3. The java.sql.Date extends java.util.Date class.      The main purpose of java.sql.Date  is to represent SQL DATE, which keeps years, months and days. This class does not keep time data information. In fact, the date is stored as milliseconds since the 1st of January 1970 00:00:00 GMT and the time part are normalized, i.e. set to zero.
  4. As I said above java.sql.Date is a wrapper around java.util.Date that handles SQL specific requirements. java.sql.Date should be used only when you are dealing with databases.
  5. You must note that java.sql.Date doesn’t hold timezone information if we required timezone conversion between our local environment and database server that depends on an implementation of JDBC driver. This adds another level of complexity.
  6. You should also keep in mind in order to support other SQL data types: SQL TIME and SQL TIMESTAMP, two others sql. * classes are available: java.sql.Time and java.sql.Timestamp.

 

You May also Like:

Can we call static method with null object?
Can we override static method in Java?
What will be the output of following java program?

That’s all about  What is the difference Between java.util.Date and java.sql.Date in Java ?
If you have any feedback or suggestion please feel free to drop in blow comment box.

Leave a Reply

Your email address will not be published. Required fields are marked *