• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Oracle Date to Java Calendar

 
Marc LeClerc
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • 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
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64959
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Sorry . It has been changed
 
Marc LeClerc
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • 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 ?
 
Paul Clapham
Sheriff
Posts: 21114
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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
  • 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
Sheriff
Posts: 21114
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Marc LeClerc
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That syntax truncates the time.

That's what I tried 1st .

I am so confused.
 
Kevin Braun
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • 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() )
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic