Hi,
I have a few questions regarding the exact way that Connector/J handles/retrieves/converts Time Zones.
Setup: I have a server on which both my MySQL server and JVM are running. My MySQL server's GLOBAL timezone is set to GMT+10:00, my system time is set to Australian/Eastern (normally GMT+10:00, but DST=GMT+11:00 from ~October-March).
I am writing a java application that works entirely in GMT+10:00, and which needs to collect dates stored in the MySQL database, all of which are stored in DATETIME fields.
I am trying to use ResultSet.getTimestamp(DATETIMEField,GMT+10Calendar) to retrieve the dates from the database and use them in the application. However, despite the fact that I am using useTimezones=true in the connection URL, all dates that fall within DST according to my SYSTEM TIME are displayed as 1 hour too early (08:00 when should display 9:00, using a SimpleDateFormat(java.sql.TimeStamp) configured to use GMT+10:00).
What I think is happening is this: MySQL is passing the date correctly to the JDBC as a String (or similarly static object) formatted as GMT+10:00. However JDBC is unable to work out (for whatever reason, I could easily have something set up incorrectly) what timezone this is supposed to be in, and so interprets it as being in SYSTEM TIME, meaning that the date stored is ONE HOUR TOO EARLY relative to UTC. When this intermediate date object is retrieved from the ResultSet as a java.sql.TimeStamp using ResultSet.getTimestamp(Field,Calendar), where calendar is a GMT+10:00 calendar, the resulting date is again one hour too early.
Does this sound plausible (are DATETIME fields stored as dates in ResultSets?), and is this the correct behaviour?
I figure that in order to solve this problem, I should set serverTimezone=GMT+10:00 and useTimeZone=true, as I assume that setting serverTimezone will inform JDBC how to interpret dates from MySQL. Does this setting also set the session timezone in MySQL? However I cannot seem to find or work out the correct syntax for setting serverTimezone to be an offset from GMT/UTC. I can only set it to timezones represented by strings (eg. GMT,MST,EST) which is of little use. Though I have found that setting serverTimezone=GMT and then interpreting the date with ResultSet.getTimestamp(Field,Calendar) using a GMT Calendar produces the desired result, however this feels a little clunky...
Any help would be much appreciated.