This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Oracle Date convert to java timestamp with new timezone

 
Marc LeClerc
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am doing a select of say logintime from an oracle table in JDBC.

I now want to take this logintime and manipulate it to a different timezone which is in a StringBean and output the new time with only the timezone changed to an xml message.

Here is what I have and it is outputting garbage. Please help.



Thanks

Marc

 
Paul Clapham
Sheriff
Posts: 21567
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Garbage? It would help if you could be a bit more specific.

And I assume that it's the userActivityImpl object which you want to display a different timezone. I'm not exactly sure what that would look like, but if your only tool to communicate that timezone is a Date object, then you're sunk. Because a Date object doesn't contain a timezone.

That said, I've had to do something rather like what your code does. I had a Date object which came from a different time zone that my system's default, and the JDBC driver producing that object screwed up the timezone aspect so it was 8 or 9 hours off. The fix for that was to use two Calendar objects with different timezones. Then there was code like "calendarRight.set(Calendar.YEAR, calendarWrong.get(CalendarYEAR))" to copy the raw numbers over. However before you try that -- because I doubt it's going to help you -- I'd suggest describing your problem in a bit more detail.
 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this actually a JDBC problem? Are you having problems obtaining the correct timezone from Oracle's TIMESTAMP WITH TIMEZONE column?

(There was a bug in Oracle's JDBC drivers, which caused the timezone to be always set to UTC - or something like that. Newer version of the driver fixed that bug, but for backward compatibility a special property needs to be set to obtain the correct behavior. I can try to dig out the details, but want to make sure they would be relevant to you.)
 
Winston Gutkowski
Bartender
Pie
Posts: 10571
64
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Marc LeClerc wrote:I am doing a select of say logintime from an oracle table in JDBC.
I now want to take this logintime and manipulate it to a different timezone which is in a StringBean and output the new time with only the timezone changed to an xml message.

Sounds to me like you haven't read the tutorials (or you could try ABriefHistoryOfJavaTime) because, as I believe was pointed out in your other thread, Java dates have no concept of timezone, they are simply a value.

If you are pulling them from an SQL DATE or TIMESTAMP field via JDBC then they will normally be converted to either java.sql.Date or java.sql.Timestamp, both of which are thin wrappers around Java's own Date class (java.util.Date).

If you want to convert them to a String (as I suspect you will for an XML file) you will need to use a DateFormat - the easiest of which to use is SimpleDateFormat (and I would suggest strongly that you use an ISO 8601 format WITH a timezone). If you try anything else, you will almost certainly be screwing up the date value you have.

Winston
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic