RE: jdbc with datetime field - unwanted timezone conversion

From: Carb Simien [MSFT] (CarbinoS_at_online.microsoft.com)
Date: 08/31/04


Date: Tue, 31 Aug 2004 22:06:56 GMT


--------------------
| Thread-Topic: jdbc with datetime field - unwanted timezone conversion
| thread-index: AcSMj5gnHbLf5bAYTqOU3MRZc9R5+Q==
| X-WBNR-Posting-Host: 209.63.42.209
| From: =?Utf-8?B?VmlydHVhbCBQcm9ncmFtbWVy?= <Virtual
Programmer@discussions.microsoft.com>
| Subject: jdbc with datetime field - unwanted timezone conversion
| Date: Fri, 27 Aug 2004 16:43:03 -0700
| Lines: 10
| Message-ID: <32B0C910-3926-4060-A13F-4014058F720C@microsoft.com>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.sqlserver.jdbcdriver
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.1.29
| Path: cpmsftngxa10.phx.gbl!TK2MSFTNGXA03.phx.gbl
| Xref: cpmsftngxa10.phx.gbl microsoft.public.sqlserver.jdbcdriver:6281
| X-Tomcat-NG: microsoft.public.sqlserver.jdbcdriver
|
| I have a database which contains records each of which has a datetime
field.
| The database machine is set up as GMT. I access this data from a
different
| machine which is running in a different timezone (EST for example). The
| value returned by the database appears to be offset by some value based
on
| the local machine's timezone. I just want the raw GMT value regardless
of
| what timezone the machine running the jdbc driver is running. Any
| suggestions how I do this?
|
| I'm using resultset.getTimestamp() and pushing that to a Calendar object
if
| that helps.
|

If you directly output the "resultset.getTimestamp()" before passing it to
the Calendar object, what is the value that is returned? Can you post the
code you are using to demonstrate this problem? If I change the Regional
Settings on my remote SQL Server to use GMT and then insert a date value, I
can query the information from a separate client machine (in a different
time zone) without a problem.

// create table datetest(col1 datetime)
// go
// insert datetest select getdate()

            Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver" );
            Connection connection =
DriverManager.getConnection("jdbc:microsoft:sqlserver://remoteSQL:1433;datab
asename=jdbc", "sa", "password");

            // Query the database
        Statement stmt = connection.createStatement();
        ResultSet rs = null;
            rs = stmt.executeQuery("select col1 from datetest");
        while (rs.next())
        {
                Timestamp ts = rs.getTimestamp(1);
                System.out.println(ts);
        }
        rs.close();
        stmt.close();
            connection.close();

Carb Simien, MCSE MCDBA MCAD
Microsoft Developer Support - Web Data

Please reply only to the newsgroups.
This posting is provided "AS IS" with no warranties, and confers no rights.

Are you secure? For information about the Strategic Technology Protection
Program and to order your FREE Security Tool Kit, please visit
http://www.microsoft.com/security.


Loading