gisly
gisly

Reputation: 683

Oracle Date and EJB Date

I have got a column of type DATE in my Oracle DB. 06.09.12 is one of the values stored there. I also have an EJB-entity mapped to the table, which has a member field "date" of type java.util.Date. However, the getter method returns the date stored in the table plus one day, e. g. 07.09.12 instead of 06.09.12. How can I get exactly the date stored? Should I consider using Timestamp?

Upvotes: 0

Views: 746

Answers (1)

Andrew Alcock
Andrew Alcock

Reputation: 19651

You may have different timezones - the timezone on the DB is different from the timezone set in Java. The underlying time is actually the same, but, for example, the date on the DB is interpreted in GMT and the Java as Eastern time. After midnight at GMT, GMT is one day ahead for 7 or so hours.

Both these timezones default to the timezone of the server, but can be overridden by the DB installation and the Java VM.

To test if this is the case, on Oracle:

select dbtimezone,sessiontimezone from dual;

And on Java:

TimeZone tz = Calendar.getInstance().getTimeZone();
System.out.println("TimeZone: "+tz.getDisplayName());

Upvotes: 2

Related Questions