Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why java.sql.Date?

 
Sainudheen Mydeen
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.)
 
sing
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6450
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34973
379
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic