Hi,
When using Java's sql ResultSet class I've used getDate() to retreive a
date. However Java 1.5 makes clear Date is deprecated.
My code to get the date (actually I'm interested only in the year although
the MySQL 'date' type is used in the table) looks like this:
Date date = results.getDate("year");
int year = date.getYear() + 1900; // +1900 == yuck
It works fine, but the compiler says:
Note: C:\...\java\...\FilmDB.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Am I missing the way I should be doing this? Or am I correct in using part
of the deprecated API?
Thanks,
MS
Mark Matthews - 02 Feb 2005 16:44 GMT
> Hi,
>
[quoted text clipped - 18 lines]
>
> MS
MS,
Touching any of Date's accessors is deprecated, one because they're not
localized, and two, because it causes static synchronization, thus
causing your application to be effectively single-threaded at that point.
The 'right' way to do things is to create a new Calendar instance from
the millisecond value in the Date instance:
Calendar cal = Calendar.getInstance();
cal.setDate(date);
And then use the accessors available on Calendar to get your values.
-Mark
Mark Matthews - 02 Feb 2005 16:44 GMT
> Hi,
>
[quoted text clipped - 18 lines]
>
> MS
MS,
Touching any of Date's accessors is deprecated, one because they're not
localized, and two, because it causes static synchronization, thus
causing your application to be effectively single-threaded at that point.
The 'right' way to do things is to create a new Calendar instance from
the millisecond value in the Date instance:
Calendar cal = Calendar.getInstance();
cal.setDate(date);
And then use the accessors available on Calendar to get your values.
-Mark
Mark Matthews - 02 Feb 2005 17:52 GMT
> Hi,
>
[quoted text clipped - 18 lines]
>
> MS
MS,
Touching any of Date's accessors is deprecated, one because they're not
localized, and two, because it causes static synchronization, thus
causing your application to be effectively single-threaded at that point.
The 'right' way to do things is to create a new Calendar instance from
the millisecond value in the Date instance:
Calendar cal = Calendar.getInstance();
cal.setTime(date);
And then use the accessors available on Calendar to get your values.
-Mark