Subject RE: [Firebird-Java] Re: time zone problem
Author Rick DeBay
Be wary of using static Calendars and parsers. They set instance
variables during calculations, and if you use the same parser at the
same time in two different threads, they'll step on each others'
results.

-----Original Message-----
From: rwilcom [mailto:ron.wilcom@...]
Sent: Thursday, July 29, 2004 8:54 AM
To: Firebird-Java@yahoogroups.com
Subject: [Firebird-Java] Re: time zone problem

Roman,

I believe I am setting the timezone correctly for the calendar
object - setting as follows:

private static final Calendar GMT = Calendar.getInstance
(TimeZone.getTimeZone("GMT") );

I am using the machine locale (which would be US/en) but that should
not impact the time zone. Reminder, if I change the OS timezone
setting the inserted date value changes!? This should never be the
case when using:

ps.setTimestamp(1, new java.sql.Timestamp( testDateTime.getTime()),
GMT );

Even if the calander object was wrongly set to a different timezone
the entry inserted into the database should be consistent even when
the OS timezone is changed. The driver should not relay on or use
the OS timezone setting to calculate the date/time entry from the
UTC millisec value?!

Also - I did upgrade to RC4 and the same problem occurs.

From my code snippet below you should easily be able to recreate
this problem. Please advise! Meanwhile, I will look into the JDBC
source code.

thanks,
Ron

start code snippet-----------------------


//assuming you have a connection object
//already connected via JayBird JDBC

Calendar GMT = Calendar.getInstance(TimeZone.getTimeZone
("GMT") ); //machine locale
PreparedStatement ps = null;
try {
ps = connection.prepareStatement("INSERT INTO MyTable(id,
dateAndtimeInGMT) VALUES (?, ?)");

ps.setInt(1, 1 );

Date testDate = format.parse("02-10-2004 10:00:00 EST");
ps.setTimestamp(2, new java.sql.Timestamp( testDate.getTime()),
GMT );

ps.executeUpdate();

//check the database value; this will be
//dependent on your OS time zone
//not on the GMT calculated value;
//After running this once change
//your OS time zone and run again -
//a different date/time value is inserted
}
catch (SQLException e){
System.out.println("error:"+e.toString());
}
finally{
try{ps.close();}
catch(Exception any){/*nothing*/}
}


end code snippet-----------------------


--- In Firebird-Java@yahoogroups.com, "Roman Rokytskyy"
<rrokytskyy@a...> wrote:
> > Date testDateTime= format.parse("02-10-2004 10:00:00 EST");
>
> > ps.setTimestamp(1, new java.sql.Timestamp( testDateTime.getTime
()),
> > GMT );
>
> Please ensure that your GMT calendar has the time zone set
correctly (i.e.
> it is not the default time zone). If you still believe that there
is a bug,
> please prepare a test case that reproduces the problem.
>
> If you want to check sources, please see
> org.firebirdsql.jdbc.field.FBTimestampField and
org.firebirdsql.gds.XSQLVAR
> classes.
>
> Roman





Yahoo! Groups Links