| Author |
Why java.sql.Date?
|
Sainudheen Mydeen
Ranch Hand
Joined: Aug 18, 2003
Posts: 218
|
|
Hi There are two Date classes. java.util.Date and java.sql.Date. All I could see additional in sql.Date is the method valueOf(String s) which Converts a string in JDBC date escape format to a Date value. Rest all available in util.Date. Can some body give me an idea why sun is keeping sql.Date? (Just for one function?). Or I misunderstood? Also when to select which Date class? Thanks -Sainudheen [ October 08, 2003: Message edited by: Sainudheen Mydeen ]
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24057
|
|
|
java.sql.Date is newer than java.util.Date. The one sql-related function would be inappropriate to add to java.util.Date, and using a class from java.sql would be out of place in non-JDBC code, so having both classes is worthwhile. The java.sql version also restricts the range of available constructors.
|
[Jess in Action][AskingGoodQuestions]
|
 |
Pradeep bhatt
Ranch Hand
Joined: Feb 27, 2002
Posts: 8876
|
|
|
http://www.onjava.com/pub/a/onjava/2003/06/05/java_calendar.html
|
Groovy
|
 |
Ilja Preuss
author
Sheriff
Joined: Jul 11, 2001
Posts: 14112
|
|
From the above link:
Like java.util.Date, all three classes in the SQL package are thin wrappers around a numeric value representing a point in time. The Date and Time classes ignore the information regarding the time of day or the calendar date, respectively. The Timestamp class, however, not only includes the usual time and date information up to millisecond precision, but also allows storing additional data to accurately represent a point in time with nanosecond precision. (A nanosecond is a billionth of a second.)
|
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
|
 |
sing
Ranch Hand
Joined: Nov 29, 2001
Posts: 121
|
|
hi, what i understand is that, java.sql.Date can used to compare the date value that return from query statement whereas java.util.Date cannot function this. steffy
|
 |
Jason Menard
Sheriff
Joined: Nov 09, 2000
Posts: 6450
|
|
The thing to keep in mind with a java.sql.Date is that the hours, minutes, seconds, and milliseconds are set to 0. I believe this was't the case prior to JSDK 1.4, but it was fixed in order to comply with the SQL standard, where SQL Date values don't have time components. If you need finer granularity than that provided by java.sql.Date, use java.sql.TimeStamp. [ October 09, 2003: Message edited by: Jason Menard ]
|
Jason's Blog
|
 |
Jeanne Boyarsky
internet detective
Marshal
Joined: May 26, 2003
Posts: 26184
|
|
Jason,
I believe this was't the case prior to JSDK 1.4, but it was fixed in order to comply with the SQL standard, where SQL Date values don't have time components.
It is fixed in 1.3 as well.
|
[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
|
 |
 |
|
|
subject: Why java.sql.Date?
|
|
|