| Author |
Oracle Date to Java Calendar
|
Marc LeClerc
Greenhorn
Joined: May 10, 2007
Posts: 12
|
|
I am an Oracle veteran, but fairly new to Java and JDBC. I am trying to retrieve a date column from an Oracle Database and map it to a java.util.Calendar type to populate an XML document. Can someone point me in the proper direction ? Thanks. Marc
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56185
|
|
"MarcL", There aren't many rules that you need to worry about here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it. In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious. Thanks! bear JavaRanch Sheriff
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Marc LeClerc
Greenhorn
Joined: May 10, 2007
Posts: 12
|
|
|
Sorry . It has been changed
|
 |
Marc LeClerc
Greenhorn
Joined: May 10, 2007
Posts: 12
|
|
Okay, I've gotten this far: Calendar calStart = Calendar.getInstance(); calStart.setTime(rs.getDate("eff_from_date")); However, the hour is defaulting to 04, and the minutes and seconds both to 00. How can I stuff the time stamp portion of the Oracle Date into the calendar ?
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16483
|
|
|
If you want to see the time component of the database column, then use rs.getTimestamp() instead of rs.getDate(). The API documentation explains the difference between the two, I believe.
|
 |
Marc LeClerc
Greenhorn
Joined: May 10, 2007
Posts: 12
|
|
Okay now I can see it.. but how do I convert it to a Calendar item? I want to select an Oracle Date column, and have it end up as a Java Calendar type with both the date and time portion. Can someone please provide an example of this ? If I use rs.getTimeStamp, how do I then populate my calendar with this ? Calendar calEnd = Calendar.getInstance(); calEnd.setTime(rs.getTimeStamp("eff_thru_date"),calEnd); This has a compile time error on the setTime method telling with incompatible types i.e. getTimeStamp is not of type Long. If I use calEnd.setTime, this truncates the timeStamp portion. Please, can someone help. I cannot believe that I could not find an example out there someplace, but I couldn't.
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16483
|
|
|
|
 |
Marc LeClerc
Greenhorn
Joined: May 10, 2007
Posts: 12
|
|
That syntax truncates the time. That's what I tried 1st . I am so confused.
|
 |
Kevin Braun
Greenhorn
Joined: Jun 08, 2007
Posts: 1
|
|
|
Calendar takes a java.util.Date, and java.sql.Timestamp should NOT be treated as a java.util.Date (see the API doc on the former). That MAY be your problem. Try using calendar.setTime( rs.getTimestamp().getTime() )
|
 |
 |
|
|
subject: Oracle Date to Java Calendar
|
|
|