List:MySQL and Java« Previous MessageNext Message »
From:Shankar Unni Date:January 22 2003 12:45am
Subject:Question about PreparedStatement.setTimestamp(..., Calendar)
View as plain text  
I asked this on the JDC site, but didn't get much of a response there.
Basically, this is about the precise semantics of the "Calendar"
argument to PreparedStatement.setTimestamp().

Here's what I'd like to do: since most databases don't understand
timezones, I'd like to convert timestamps to UTC equivalents. E.g. I'm
in the Pacific timezone, so if I have a timestamp corresponding to Jan
20, 12 Noon PST, I'd like the database column to be recorded as "Jan 20,
8PM" (because that's what the timestamp would read if it were formatted
using a UTC calendar).

I'm using

   Calendar utc_cal = Calendar.getInstance("UTC")

and am calling

   PreparedStatement ps = ...;
   ps.setTimestamp(n, ts, utc_cal);

What actually happens is that:

* With Oracle, the time gets written into the database as 2003-01-20
20:00:00 (what I'd expect).

* MySQL (connector/J 3.0.4) on the other hand, interprets this as "I'm
saying that I'm in UTC, and so convert it to what the server expects",
so it actually does the opposite transformation: 2003-01-20 04:00:00 is
what gets written into the DB.

Who's correct?

Certainly the language in the Javadoc needs to be tightened
considerably, if two people can read such radically different things
into the spec..

Thread
Question about PreparedStatement.setTimestamp(..., Calendar)Shankar Unni22 Jan
  • Re: Question about PreparedStatement.setTimestamp(..., Calendar)Mark Matthews22 Jan
    • RE: Question about PreparedStatement.setTimestamp(..., Calendar)Shankar Unni22 Jan
      • Re: Question about PreparedStatement.setTimestamp(..., Calendar)Mark Matthews22 Jan
        • RE: Question about PreparedStatement.setTimestamp(..., Calendar)Shankar Unni22 Jan
          • Re: Question about PreparedStatement.setTimestamp(..., Calendar)Mark Matthews22 Jan
            • RE: Question about PreparedStatement.setTimestamp(..., Calendar)Shankar Unni22 Jan
      • Re: Question about PreparedStatement.setTimestamp(..., Calendar)Mark Matthews22 Jan
  • Re: Question about PreparedStatement.setTimestamp(..., Calendar)David Morse22 Jan