Re: (Again) java.util.Date vs java.sql.Date
(Again) Im trying to understand the EXACT difference between
java.util.Date vs java.sql.Date.
Googling, I can see that this is a very "popular" subject, but I still
cannot figure out it exactly.
Many writers claim that java.sql.Date only stores the DATE part (yyyy-
mm-dd) but not the TIME part (hh:MM:ss) of a Date/Time value, but that
I can easily disprove:
java.util.Date ud = new java.util.Date();
java.sql.Date sd = new java.sql.Date(ud.getTime());
So, apparently, java.sql.Date and java.util.Date have THE SAME
precision (at least down to the millisecs...).
java.sql.Date extends java.util.Date and uses it for storage, so
obviously they store "the same information".
And the official API documentation, really looks more confusing than
helpful to me::
A thin wrapper around a millisecond value that allows JDBC to identify
this as an SQL DATE value. A milliseconds value represents the
number of milliseconds that have passed since January 1, 1970
To conform with the definition of SQL DATE, the millisecond values
wrapped by a java.sql.Date instance must be 'normalized' by setting
the hours, minutes, seconds, and milliseconds to zero in the
particular time zone with which the instance is associated. "
Exactly what means "an SQL DATE value" ?
DATE is a database type that only contains date part no time part.
When a Java Date contains zeroes for h, m, s and ms then it
matches perfectly with the database type DATE.
How EXACTLY does it differ
from a java.util.Date value?
Functionally: the toString method only shows y, m and d.
But programming wise it provides type safety.
Most importantly: WHY does JDBC *need* to distinguish between them?
It forces the programmer to distinguish between the 3 different types:
date + time