Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Databases / February 2005

Tip: Looking for answers? Try searching our database.

ResultSet's getDate() -- Date is deprecated

Thread view: 
MS - 02 Feb 2005 16:29 GMT
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.