Lists: | pljava-dev |
---|
From: | gm at winls(dot)com (George McQuade) |
---|---|
To: | |
Subject: | [Pljava-dev] date handling... |
Date: | 2005-08-14 04:45:17 |
Message-ID: | 1123994718.4039.9.camel@sat1 |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pljava-dev |
Hello list,
We have successfully installed pljava on a postgres 7.4.1 system running
under Fedora Core 1. Everything seems to work fine except for a date
handling issue.
The listed function attempts to retrieve a date from the db.
The birthdate column is of pg type "Date".
The logger will output "Birthdate 2005-07-31"
The birthdate stored for custid=385 is 2005-08-01.
Seems the builtin pljava jdbc driver is performing some sort of timezone
adjustment. Has anyone run into this before?
Thanks
george
package winls.dbdata.pljava;
import java.sql.*;
import java.util.logging.*;
import org.postgresql.pljava.*;
import java.util.Date;
/**
*
* @author user
*/
public class DateFunc {
public static void getBirthDate(){
try {
Statement m_statement =
DriverManager.getConnection("jdbc:default:connection").createStatement();
String query="select birthdate from customers where custid
=385 ";
ResultSet rs=m_statement.executeQuery(query);
if(rs != null)
while(rs.next()){
Logger.getAnonymousLogger().info("Birthdate
"+rs.getDate(1));
}
}
catch (Exception e){
Logger.getAnonymousLogger().info(""+e.getMessage());
}
}
}
From: | thhal at mailblocks(dot)com (Thomas Hallgren) |
---|---|
To: | |
Subject: | [Pljava-dev] date handling... |
Date: | 2005-08-14 08:13:07 |
Message-ID: | thhal-0mJXaA8vb77Q90ldIzVVlM69mQSE96J@mailblocks.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pljava-dev |
George,
This is probably a bug. PL/Java has to do some adjustements in order to
get java.sql.Date to work correctly but something is obviously wrong.
A java.sql.Date in java extends from java.util.Date. It's internal
representation is in milliseconds since midnight 1970-01-01. If the
timezone used by your server differs from the one that the JVM uses,
"midnight" may be translated some time in the evening the day before.
Can you please print the timezone that your server uses and the timezone
that the JVM thinks it has, i.e. TimeZone.getDefault() and see if
there's a differenence?
Regards,
Thomas Hallgren
George McQuade wrote:
>Hello list,
>
>We have successfully installed pljava on a postgres 7.4.1 system running
>under Fedora Core 1. Everything seems to work fine except for a date
>handling issue.
>
>The listed function attempts to retrieve a date from the db.
>
>The birthdate column is of pg type "Date".
>
>The logger will output "Birthdate 2005-07-31"
>The birthdate stored for custid=385 is 2005-08-01.
>
>Seems the builtin pljava jdbc driver is performing some sort of timezone
>adjustment. Has anyone run into this before?
>
>Thanks
>
>george
>
>package winls.dbdata.pljava;
>
>import java.sql.*;
>import java.util.logging.*;
>import org.postgresql.pljava.*;
>import java.util.Date;
>/**
> *
> * @author user
> */
>public class DateFunc {
>
> public static void getBirthDate(){
> try {
> Statement m_statement =
>DriverManager.getConnection("jdbc:default:connection").createStatement();
> String query="select birthdate from customers where custid
>=385 ";
> ResultSet rs=m_statement.executeQuery(query);
> if(rs != null)
> while(rs.next()){
> Logger.getAnonymousLogger().info("Birthdate
>"+rs.getDate(1));
> }
> }
> catch (Exception e){
> Logger.getAnonymousLogger().info(""+e.getMessage());
> }
> }
>
>
>}
>
>_______________________________________________
>Pljava-dev mailing list
>Pljava-dev at gborg.postgresql.org
>http://gborg.postgresql.org/mailman/listinfo/pljava-dev
>
>
From: | gm at winls(dot)com (George McQuade) |
---|---|
To: | |
Subject: | [Pljava-dev] date handling... |
Date: | 2005-08-18 03:46:28 |
Message-ID: | 1124336789.2862.7.camel@sat1 |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pljava-dev |
Thanks for the response Thomas.
The timezones are indeed different. show all from psql shows Time Zone
as 'undefined'. The jvm returns CST6CDT.
We forced the timezone in the db server to 'CST6CDT' and the one 1 day
difference is still there.
We set the timezone in the db server to 'GMT' and pl/java returns the
correct date, no 1 day difference at all.
I think I read somewhere that it is a good practice to set the db server
time to GMT and let the client specify the client's timezone. We are now
in the process of testing our db server/client software to interact
against db servers running in GMT, seems to be the choice most people
use.
Thanks again.
george
On Sun, 2005-08-14 at 03:13, Thomas Hallgren wrote:
> George,
> This is probably a bug. PL/Java has to do some adjustements in order to
> get java.sql.Date to work correctly but something is obviously wrong.
>
> A java.sql.Date in java extends from java.util.Date. It's internal
> representation is in milliseconds since midnight 1970-01-01. If the
> timezone used by your server differs from the one that the JVM uses,
> "midnight" may be translated some time in the evening the day before.
>
> Can you please print the timezone that your server uses and the timezone
> that the JVM thinks it has, i.e. TimeZone.getDefault() and see if
> there's a differenence?
>
> Regards,
> Thomas Hallgren