• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Oracle Date to Java Calendar

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"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
 
Marc LeClerc
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry . It has been changed
 
Marc LeClerc
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ?
 
Marshal
Posts: 28294
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Marshal
Posts: 28294
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Marc LeClerc
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That syntax truncates the time.

That's what I tried 1st .

I am so confused.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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() )
 
It's feeding time! Give me the food you were going to give to this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic