In this post we will discuss What is the difference Between java.util.Date and java.sql.Date in Java ?
- As per Java documentation java.sql.Date is a wrapper around millisecond value which is used by JDBC to identify an SQL DATE type.
- 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.
- 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.
- 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.
- 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.
- 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:
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.