pg.ddx.io pgsql-interfaces@postgresql.org mailing list archive
help / color / mirror / Atom feedJDBC date problem
12+ messages / 7 participants
[nested] [flat]
* JDBC date problem
@ 1998-10-16 06:20 Aleksey Demakov <avd@gcom.ru>
0 siblings, 2 replies; 12+ messages in thread
From: Aleksey Demakov @ 1998-10-16 06:20 UTC (permalink / raw)
To: pgsql-interfaces; peter@retep.org.uk
Can you believe me?
I have a table with a column which is to store the dates each row was
created. I fill it with the line:
insert_stmt.setDate(2, new Date (System.currentTimeMillis ()));
And every day I insert a new row I can see that I did it tomorrow!
I have found that in the method PreparedStatement.setDate() the date
argument is intentionally incremented by one. The comments there say
that it's to compensate broken SimpleDateFormat. Apparently, my
SimpleDateFormat is ok (JDK 1.1.7 for win95/nt and jdk1.1.5 for freebsd).
Aleksey
--
Aleksey Demakov
avd@gcom.ru
^ permalink raw reply [nested|flat] 12+ messages in thread
* Re: JDBC date problem
@ 1998-10-16 17:17 Peter T Mount <peter@retep.org.uk>
parent: Aleksey Demakov <avd@gcom.ru>
1 sibling, 0 replies; 12+ messages in thread
From: Peter T Mount @ 1998-10-16 17:17 UTC (permalink / raw)
To: Aleksey Demakov <avd@gcom.ru>; +Cc: pgsql-interfaces
On 16 Oct 1998, Aleksey Demakov wrote:
>
> Can you believe me?
>
> I have a table with a column which is to store the dates each row was
> created. I fill it with the line:
>
> insert_stmt.setDate(2, new Date (System.currentTimeMillis ()));
>
> And every day I insert a new row I can see that I did it tomorrow!
>
> I have found that in the method PreparedStatement.setDate() the date
> argument is intentionally incremented by one. The comments there say
> that it's to compensate broken SimpleDateFormat. Apparently, my
> SimpleDateFormat is ok (JDK 1.1.7 for win95/nt and jdk1.1.5 for freebsd).
Yep. Prior to JDK 1.1.6, setDate() had a bug, where it stored the date 1
day earlier than it really was. I tested both Linux & Win95/nt jdk's, and
this seemed consistent.
About 1 1/2 months ago, I found that 1.1.6 fixed it, so I removed the
increment from the source.
The V6.4 beta driver effectively only works for 1.1.6 or later JDK for the
setDate() method.
--
Peter T Mount peter@retep.org.uk
Main Homepage: http://www.retep.org.uk
PostgreSQL JDBC Faq: http://www.retep.org.uk/postgres
Java PDF Generator: http://www.retep.org.uk/pdf
^ permalink raw reply [nested|flat] 12+ messages in thread
* Re: [INTERFACES] JDBC date problem
@ 1998-10-18 10:02 Herouth Maoz <herouth@oumail.openu.ac.il>
parent: Aleksey Demakov <avd@gcom.ru>
1 sibling, 1 reply; 12+ messages in thread
From: Herouth Maoz @ 1998-10-18 10:02 UTC (permalink / raw)
To: Aleksey Demakov <avd@gcom.ru>; pgsql-interfaces; peter@retep.org.uk
At 8:20 +0200 on 16/10/98, Aleksey Demakov wrote:
>
> Can you believe me?
>
> I have a table with a column which is to store the dates each row was
> created. I fill it with the line:
>
> insert_stmt.setDate(2, new Date (System.currentTimeMillis ()));
>
> And every day I insert a new row I can see that I did it tomorrow!
>
> I have found that in the method PreparedStatement.setDate() the date
> argument is intentionally incremented by one. The comments there say
> that it's to compensate broken SimpleDateFormat. Apparently, my
> SimpleDateFormat is ok (JDK 1.1.7 for win95/nt and jdk1.1.5 for freebsd).
For some, it works like that, and for some it doesn't. I'll leave it to the
author of the JDBC driver to explain why this is done. The question I ask
is: why do you use the Java current date instead of doing this within the
INSERT itself?
That is, if the column to contain the row creation date is of type
DATETIME, just use now() instead of a ? and a setDate.
INSERT INTO my_table
(creation, other_field1, other_field2, other_field3)
VALUES
('now', ?, ?, ?);
Personally, I do this by defining the creation column as a NOT NULL and
giving it a default (There's a bit of a trick here, because you have to use
a function, or 'now' will be interpreted as the time of the creation of the
table, so I define an SQL function which returns 'now'::DATETIME). This
enables me to use a statement like
INSERT INTO my_table
(other_field1, other_field2, other_field3)
VALUES
(?,?,?);
And not bother myself about the creation dates (which are automatic).
Herouth
--
Herouth Maoz, Internet developer.
Open University of Israel - Telem project
http://telem.openu.ac.il/~herutma
^ permalink raw reply [nested|flat] 12+ messages in thread
* Re: [INTERFACES] JDBC date problem
@ 1998-10-19 05:44 Peter T Mount <peter@retep.org.uk>
parent: Herouth Maoz <herouth@oumail.openu.ac.il>
0 siblings, 1 reply; 12+ messages in thread
From: Peter T Mount @ 1998-10-19 05:44 UTC (permalink / raw)
To: Herouth Maoz <herouth@oumail.openu.ac.il>; +Cc: Aleksey Demakov <avd@gcom.ru>; pgsql-interfaces
On Sun, 18 Oct 1998, Herouth Maoz wrote:
> At 8:20 +0200 on 16/10/98, Aleksey Demakov wrote:
>
>
> >
> > Can you believe me?
> >
> > I have a table with a column which is to store the dates each row was
> > created. I fill it with the line:
> >
> > insert_stmt.setDate(2, new Date (System.currentTimeMillis ()));
> >
> > And every day I insert a new row I can see that I did it tomorrow!
> >
> > I have found that in the method PreparedStatement.setDate() the date
> > argument is intentionally incremented by one. The comments there say
> > that it's to compensate broken SimpleDateFormat. Apparently, my
> > SimpleDateFormat is ok (JDK 1.1.7 for win95/nt and jdk1.1.5 for freebsd).
>
> For some, it works like that, and for some it doesn't. I'll leave it to the
> author of the JDBC driver to explain why this is done. The question I ask
> is: why do you use the Java current date instead of doing this within the
> INSERT itself?
The bug is with pre 1.1.6 JDK's, and occurs when you set a Date. For some
reason, it set's it 1 day behind the real value. Sun fixed this bug with
the 1.1.6 release.
> That is, if the column to contain the row creation date is of type
> DATETIME, just use now() instead of a ? and a setDate.
>
> INSERT INTO my_table
> (creation, other_field1, other_field2, other_field3)
> VALUES
> ('now', ?, ?, ?);
>
> Personally, I do this by defining the creation column as a NOT NULL and
> giving it a default (There's a bit of a trick here, because you have to use
> a function, or 'now' will be interpreted as the time of the creation of the
> table, so I define an SQL function which returns 'now'::DATETIME). This
> enables me to use a statement like
>
> INSERT INTO my_table
> (other_field1, other_field2, other_field3)
> VALUES
> (?,?,?);
>
> And not bother myself about the creation dates (which are automatic).
This is a valid point, and for his case, I'd agree with you.
The Date problem is going to be with us as long as people are still using
pre 1.1.6 JDK's.
I did think of making the driver sence if the bug is present, and then to
account for it, but decided against it, on the grounds of performance.
--
Peter T Mount peter@retep.org.uk
Main Homepage: http://www.retep.org.uk
PostgreSQL JDBC Faq: http://www.retep.org.uk/postgres
Java PDF Generator: http://www.retep.org.uk/pdf
^ permalink raw reply [nested|flat] 12+ messages in thread
* Re: [INTERFACES] JDBC date problem
@ 1998-10-19 08:13 Aleksey Demakov <avd@gcom.ru>
parent: Peter T Mount <peter@retep.org.uk>
0 siblings, 1 reply; 12+ messages in thread
From: Aleksey Demakov @ 1998-10-19 08:13 UTC (permalink / raw)
To: Peter T Mount <peter@retep.org.uk>; +Cc: Herouth Maoz <herouth@oumail.openu.ac.il>; pgsql-interfaces
Peter T Mount <peter@retep.org.uk> writes:
>
> > That is, if the column to contain the row creation date is of type
> > DATETIME, just use now() instead of a ? and a setDate.
> >
> > INSERT INTO my_table
> > (creation, other_field1, other_field2, other_field3)
> > VALUES
> > ('now', ?, ?, ?);
> >
> > Personally, I do this by defining the creation column as a NOT NULL and
> > giving it a default (There's a bit of a trick here, because you have to use
> > a function, or 'now' will be interpreted as the time of the creation of the
> > table, so I define an SQL function which returns 'now'::DATETIME). This
> > enables me to use a statement like
> >
> > INSERT INTO my_table
> > (other_field1, other_field2, other_field3)
> > VALUES
> > (?,?,?);
> >
> > And not bother myself about the creation dates (which are automatic).
>
> This is a valid point, and for his case, I'd agree with you.
Indeed, in my case this is much better solution. Many thanks to Herouth.
> The Date problem is going to be with us as long as people are still using
> pre 1.1.6 JDK's.
Not quite. Also as long as people are using post 1.1.6 JDK's with the
6.3.2 driver.
> I did think of making the driver sence if the bug is present, and then to
> account for it, but decided against it, on the grounds of performance.
As for me it's ok.
--
Aleksey Demakov
avd@gcom.ru
^ permalink raw reply [nested|flat] 12+ messages in thread
* Re: [INTERFACES] JDBC date problem
@ 1998-10-19 17:15 Peter T Mount <peter@retep.org.uk>
parent: Aleksey Demakov <avd@gcom.ru>
0 siblings, 0 replies; 12+ messages in thread
From: Peter T Mount @ 1998-10-19 17:15 UTC (permalink / raw)
To: Aleksey Demakov <avd@gcom.ru>; +Cc: Herouth Maoz <herouth@oumail.openu.ac.il>; pgsql-interfaces
On 19 Oct 1998, Aleksey Demakov wrote:
> Peter T Mount <peter@retep.org.uk> writes:
> >
> > > That is, if the column to contain the row creation date is of type
> > > DATETIME, just use now() instead of a ? and a setDate.
> > >
> > > INSERT INTO my_table
> > > (creation, other_field1, other_field2, other_field3)
> > > VALUES
> > > ('now', ?, ?, ?);
> > >
> > > Personally, I do this by defining the creation column as a NOT NULL and
> > > giving it a default (There's a bit of a trick here, because you have to use
> > > a function, or 'now' will be interpreted as the time of the creation of the
> > > table, so I define an SQL function which returns 'now'::DATETIME). This
> > > enables me to use a statement like
> > >
> > > INSERT INTO my_table
> > > (other_field1, other_field2, other_field3)
> > > VALUES
> > > (?,?,?);
> > >
> > > And not bother myself about the creation dates (which are automatic).
> >
> > This is a valid point, and for his case, I'd agree with you.
>
> Indeed, in my case this is much better solution. Many thanks to Herouth.
>
> > The Date problem is going to be with us as long as people are still using
> > pre 1.1.6 JDK's.
>
> Not quite. Also as long as people are using post 1.1.6 JDK's with the
> 6.3.2 driver.
One thing with the 6.4 driver, is that it's backward compatible with
6.3.2. All of the differences between the two have been either
implementing new features, or bug fixes.
The Date problem is the only incompatible change.
> > I did think of making the driver sence if the bug is present, and then to
> > account for it, but decided against it, on the grounds of performance.
>
> As for me it's ok.
>
> --
> Aleksey Demakov
> avd@gcom.ru
>
--
Peter T Mount peter@retep.org.uk
Main Homepage: http://www.retep.org.uk
PostgreSQL JDBC Faq: http://www.retep.org.uk/postgres
Java PDF Generator: http://www.retep.org.uk/pdf
^ permalink raw reply [nested|flat] 12+ messages in thread
* JDBC date problem
@ 2001-01-09 02:40 Mike Cannon-Brookes <mike@bookmarkbox.com>
0 siblings, 0 replies; 12+ messages in thread
From: Mike Cannon-Brookes @ 2001-01-09 02:40 UTC (permalink / raw)
To: pgsql-interfaces
I'm having a problem with dates in the JDBC driver. They are being mangled
when they come through from the database, here are some examples:
> Postgres: Java:
> 2000-12-20 16:11:00+11 Nov 20 16:00:00 EST 2000
(looks like it's pulling the month from the timezone or minute field?)
It gets worse ;)
> Postgres: Java:
> 2001-01-03 17:35:00+11 Nov 03 17:00:00 EST 2003
(again, month comes from the timezone field, but 2004?! ;))
And worse still...
> Postgres: Java:
> 2001-01-02 18:41:00+11 May 02 17:00:00 EST 2004
(now I'm not really sure where anything came from here, besides the day -
every other number seems wrong?)
Some raw data:
Postgres: Java:
2000-12-20 16:11:00+11 | 2000-11-20 16:00:00
2001-01-02 18:41:00+11 | 2004-05-02 17:00:00
2001-01-03 17:35:00+11 | 2003-11-03 17:00:00
2000-12-20 15:00:00+11 | 1999-12-20 15:00:00
2001-01-04 19:00:00+11 | 2000-12-04 19:00:00
2001-01-09 11:00:00+11 | 2000-12-09 11:00:00
Any ideas? This is a real stumper and I need to find a solution asap! I'm
using a JDBC driver I built from CVS no more than a month ago.
-mike
____________________________________________________________
Mike Cannon-Brookes - Technology Director, Asia Pacific
internet.com Corporation - The Internet Industry Portal
Ph: (612) 9290 1088 - Mob: 0416 106090
- The Media Network @ http://australia.internet.com
- Meet A Guru @ http://www.breakfastforums.com.au
- Subscribe Online @ http://www.enewsletters.com.au
____________________________________________________________
^ permalink raw reply [nested|flat] 12+ messages in thread
* JDBC date problem
@ 2001-01-09 22:53 Mike Cannon-Brookes <mcannon@internet.com>
0 siblings, 1 reply; 12+ messages in thread
From: Mike Cannon-Brookes @ 2001-01-09 22:53 UTC (permalink / raw)
To: pgsql-interfaces
I'm having a problem with dates in the JDBC driver. They are being mangled
when they come through from the database, here are some examples:
> Postgres: Java:
> 2000-12-20 16:11:00+11 Nov 20 16:00:00 EST 2000
(looks like it's pulling the month from the timezone or minute field?)
It gets worse ;)
> Postgres: Java:
> 2001-01-03 17:35:00+11 Nov 03 17:00:00 EST 2003
(again, month comes from the timezone field, but 2004?! ;))
And worse still...
> Postgres: Java:
> 2001-01-02 18:41:00+11 May 02 17:00:00 EST 2004
(now I'm not really sure where anything came from here, besides the day -
every other number seems wrong?)
Some raw data:
Postgres: Java:
2000-12-20 16:11:00+11 | 2000-11-20 16:00:00
2001-01-02 18:41:00+11 | 2004-05-02 17:00:00
2001-01-03 17:35:00+11 | 2003-11-03 17:00:00
2000-12-20 15:00:00+11 | 1999-12-20 15:00:00
2001-01-04 19:00:00+11 | 2000-12-04 19:00:00
2001-01-09 11:00:00+11 | 2000-12-09 11:00:00
Any ideas? This is a real stumper and I need to find a solution asap! I'm
using a JDBC driver I built from CVS no more than a month ago.
-mike
____________________________________________________________
Mike Cannon-Brookes - Technology Director, Asia Pacific
internet.com Corporation - The Internet Industry Portal
Ph: (612) 9290 1088 - Mob: 0416 106090
- The Media Network @ http://australia.internet.com
- Meet A Guru @ http://www.breakfastforums.com.au
- Subscribe Online @ http://www.enewsletters.com.au
____________________________________________________________
^ permalink raw reply [nested|flat] 12+ messages in thread
* Re: JDBC date problem
@ 2001-01-10 09:42 Michael Stephenson <mstephenson@tirin.openworld.co.uk>
parent: Mike Cannon-Brookes <mcannon@internet.com>
0 siblings, 1 reply; 12+ messages in thread
From: Michael Stephenson @ 2001-01-10 09:42 UTC (permalink / raw)
To: pgsql-interfaces
> Any ideas? This is a real stumper and I need to find a solution asap! I'm
> using a JDBC driver I built from CVS no more than a month ago.
The results look to me like that in org.postgresql.jdbc2.ResultSet
'mm' and 'MM' have been confused (I know that this was the case in a patch
I submitted), try replacing getTimeStamp() with:
public Timestamp getTimestamp(int columnIndex) throws SQLException
{
String s = getString(columnIndex);
if(s==null)
return null;
SimpleDateFormat df = null;
if (s.length()>21 && s.indexOf('.') != -1) {
df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSzzz");
} else if (s.length()>19 && s.indexOf('.') == -1) {
df = new SimpleDateFormat("yyyy-MM-dd HH:mm:sszzz");
} else if (s.length()>19 && s.indexOf('.') != -1) {
df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SS");
} else if (s.length()>10 && s.length()<=18) {
df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
} else {
df = new SimpleDateFormat("yyyy-MM-dd");
}
try {
return new Timestamp(df.parse(s).getTime());
} catch(ParseException e) {
throw new PSQLException("postgresql.res.badtimestamp",new
Integer(e.getErrorOffset()),s);
}
}
Michael Stephenson
^ permalink raw reply [nested|flat] 12+ messages in thread
* RE: JDBC date problem
@ 2001-01-10 13:19 Mike Cannon-Brookes <mcannon@internet.com>
parent: Michael Stephenson <mstephenson@tirin.openworld.co.uk>
0 siblings, 1 reply; 12+ messages in thread
From: Mike Cannon-Brookes @ 2001-01-10 13:19 UTC (permalink / raw)
To: pgsql-interfaces
For reference, I just updated my CVS tree and recompiled using Ant and the
new jar works much better. It must be a bug in the old jar (ResultSet.java
was indeed updated with your patch Michael).
Thanks for the tip!
Mike
PS For anyone interested, org.postgresql.xa.Test has a serious bug in it,
tries to instantiate an interface (XADataSource) - someone might want to
hack at it. (just comment out the method and recompile if you care not about
testing ;))
> -----Original Message-----
> From: pgsql-interfaces-owner@postgresql.org
> [mailto:pgsql-interfaces-owner@postgresql.org]On Behalf Of Michael
> Stephenson
> Sent: Wednesday, January 10, 2001 8:42 PM
> To: Pgsql-Interfaces@Postgresql. Org
> Subject: Re: [INTERFACES] JDBC date problem
>
>
> > Any ideas? This is a real stumper and I need to find a solution
> asap! I'm
> > using a JDBC driver I built from CVS no more than a month ago.
>
> The results look to me like that in org.postgresql.jdbc2.ResultSet
> 'mm' and 'MM' have been confused (I know that this was the case in a patch
> I submitted), try replacing getTimeStamp() with:
>
> public Timestamp getTimestamp(int columnIndex) throws SQLException
> {
> String s = getString(columnIndex);
> if(s==null)
> return null;
>
> SimpleDateFormat df = null;
> if (s.length()>21 && s.indexOf('.') != -1) {
> df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSzzz");
> } else if (s.length()>19 && s.indexOf('.') == -1) {
> df = new SimpleDateFormat("yyyy-MM-dd HH:mm:sszzz");
> } else if (s.length()>19 && s.indexOf('.') != -1) {
> df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SS");
> } else if (s.length()>10 && s.length()<=18) {
> df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
> } else {
> df = new SimpleDateFormat("yyyy-MM-dd");
> }
>
> try {
> return new Timestamp(df.parse(s).getTime());
> } catch(ParseException e) {
> throw new PSQLException("postgresql.res.badtimestamp",new
> Integer(e.getErrorOffset()),s);
> }
> }
>
> Michael Stephenson
>
>
>
^ permalink raw reply [nested|flat] 12+ messages in thread
* RE: JDBC date problem
@ 2001-01-10 13:55 Mike Cannon-Brookes <mcannon@internet.com>
parent: Mike Cannon-Brookes <mcannon@internet.com>
0 siblings, 1 reply; 12+ messages in thread
From: Mike Cannon-Brookes @ 2001-01-10 13:55 UTC (permalink / raw)
To: pgsql-interfaces
Actually I've been playing around more and there's some cases left out of
the driver. I hacked it to put them in and it works much better now. (Was
giving Bad Timestamp exceptions).
I've attached the hacked / fixed ResultSet.java file as I have no CVS
access, would some kind soul with access patch it? I've marked my changes
clearly with comments in the getTimestamp() method.
Hope this helps!
Mike
> -----Original Message-----
> From: pgsql-interfaces-owner@postgresql.org
> [mailto:pgsql-interfaces-owner@postgresql.org]On Behalf Of Mike
> Cannon-Brookes
> Sent: Thursday, January 11, 2001 12:20 AM
> To: Pgsql-Interfaces@Postgresql. Org
> Subject: RE: [INTERFACES] JDBC date problem
>
>
> For reference, I just updated my CVS tree and recompiled using Ant and the
> new jar works much better. It must be a bug in the old jar (ResultSet.java
> was indeed updated with your patch Michael).
>
> Thanks for the tip!
> Mike
>
> PS For anyone interested, org.postgresql.xa.Test has a serious bug in it,
> tries to instantiate an interface (XADataSource) - someone might want to
> hack at it. (just comment out the method and recompile if you
> care not about
> testing ;))
>
> > -----Original Message-----
> > From: pgsql-interfaces-owner@postgresql.org
> > [mailto:pgsql-interfaces-owner@postgresql.org]On Behalf Of Michael
> > Stephenson
> > Sent: Wednesday, January 10, 2001 8:42 PM
> > To: Pgsql-Interfaces@Postgresql. Org
> > Subject: Re: [INTERFACES] JDBC date problem
> >
> >
> > > Any ideas? This is a real stumper and I need to find a solution
> > asap! I'm
> > > using a JDBC driver I built from CVS no more than a month ago.
> >
> > The results look to me like that in org.postgresql.jdbc2.ResultSet
> > 'mm' and 'MM' have been confused (I know that this was the case
> in a patch
> > I submitted), try replacing getTimeStamp() with:
> >
> > public Timestamp getTimestamp(int columnIndex) throws SQLException
> > {
> > String s = getString(columnIndex);
> > if(s==null)
> > return null;
> >
> > SimpleDateFormat df = null;
> > if (s.length()>21 && s.indexOf('.') != -1) {
> > df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSzzz");
> > } else if (s.length()>19 && s.indexOf('.') == -1) {
> > df = new SimpleDateFormat("yyyy-MM-dd HH:mm:sszzz");
> > } else if (s.length()>19 && s.indexOf('.') != -1) {
> > df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SS");
> > } else if (s.length()>10 && s.length()<=18) {
> > df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
> > } else {
> > df = new SimpleDateFormat("yyyy-MM-dd");
> > }
> >
> > try {
> > return new Timestamp(df.parse(s).getTime());
> > } catch(ParseException e) {
> > throw new PSQLException("postgresql.res.badtimestamp",new
> > Integer(e.getErrorOffset()),s);
> > }
> > }
> >
> > Michael Stephenson
> >
> >
> >
>
>
Attachments:
ResultSet.java (application/x-javascript, 39.2K) download
^ permalink raw reply [nested|flat] 12+ messages in thread
* Re: JDBC date problem
@ 2001-01-12 04:31 Bruce Momjian <pgman@candle.pha.pa.us>
parent: Mike Cannon-Brookes <mcannon@internet.com>
0 siblings, 0 replies; 12+ messages in thread
From: Bruce Momjian @ 2001-01-12 04:31 UTC (permalink / raw)
To: Mike Cannon-Brookes <mcannon@internet.com>; +Cc: pgsql-interfaces
Would you please send me a context diff (diff -c) comparing the two
versions? Thanks.
> Actually I've been playing around more and there's some cases left out of
> the driver. I hacked it to put them in and it works much better now. (Was
> giving Bad Timestamp exceptions).
>
> I've attached the hacked / fixed ResultSet.java file as I have no CVS
> access, would some kind soul with access patch it? I've marked my changes
> clearly with comments in the getTimestamp() method.
>
> Hope this helps!
>
> Mike
>
> > -----Original Message-----
> > From: pgsql-interfaces-owner@postgresql.org
> > [mailto:pgsql-interfaces-owner@postgresql.org]On Behalf Of Mike
> > Cannon-Brookes
> > Sent: Thursday, January 11, 2001 12:20 AM
> > To: Pgsql-Interfaces@Postgresql. Org
> > Subject: RE: [INTERFACES] JDBC date problem
> >
> >
> > For reference, I just updated my CVS tree and recompiled using Ant and the
> > new jar works much better. It must be a bug in the old jar (ResultSet.java
> > was indeed updated with your patch Michael).
> >
> > Thanks for the tip!
> > Mike
> >
> > PS For anyone interested, org.postgresql.xa.Test has a serious bug in it,
> > tries to instantiate an interface (XADataSource) - someone might want to
> > hack at it. (just comment out the method and recompile if you
> > care not about
> > testing ;))
> >
> > > -----Original Message-----
> > > From: pgsql-interfaces-owner@postgresql.org
> > > [mailto:pgsql-interfaces-owner@postgresql.org]On Behalf Of Michael
> > > Stephenson
> > > Sent: Wednesday, January 10, 2001 8:42 PM
> > > To: Pgsql-Interfaces@Postgresql. Org
> > > Subject: Re: [INTERFACES] JDBC date problem
> > >
> > >
> > > > Any ideas? This is a real stumper and I need to find a solution
> > > asap! I'm
> > > > using a JDBC driver I built from CVS no more than a month ago.
> > >
> > > The results look to me like that in org.postgresql.jdbc2.ResultSet
> > > 'mm' and 'MM' have been confused (I know that this was the case
> > in a patch
> > > I submitted), try replacing getTimeStamp() with:
> > >
> > > public Timestamp getTimestamp(int columnIndex) throws SQLException
> > > {
> > > String s = getString(columnIndex);
> > > if(s==null)
> > > return null;
> > >
> > > SimpleDateFormat df = null;
> > > if (s.length()>21 && s.indexOf('.') != -1) {
> > > df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSzzz");
> > > } else if (s.length()>19 && s.indexOf('.') == -1) {
> > > df = new SimpleDateFormat("yyyy-MM-dd HH:mm:sszzz");
> > > } else if (s.length()>19 && s.indexOf('.') != -1) {
> > > df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SS");
> > > } else if (s.length()>10 && s.length()<=18) {
> > > df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
> > > } else {
> > > df = new SimpleDateFormat("yyyy-MM-dd");
> > > }
> > >
> > > try {
> > > return new Timestamp(df.parse(s).getTime());
> > > } catch(ParseException e) {
> > > throw new PSQLException("postgresql.res.badtimestamp",new
> > > Integer(e.getErrorOffset()),s);
> > > }
> > > }
> > >
> > > Michael Stephenson
> > >
> > >
> > >
> >
> >
[ Attachment, skipping... ]
--
Bruce Momjian | http://candle.pha.pa.us
pgman@candle.pha.pa.us | (610) 853-3000
+ If your life is a hard drive, | 830 Blythe Avenue
+ Christ can be your backup. | Drexel Hill, Pennsylvania 19026
^ permalink raw reply [nested|flat] 12+ messages in thread
end of thread, other threads:[~2001-01-12 04:31 UTC | newest]
Thread overview: 12+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1998-10-16 06:20 JDBC date problem Aleksey Demakov <avd@gcom.ru>
1998-10-16 17:17 ` Peter T Mount <peter@retep.org.uk>
1998-10-18 10:02 ` Herouth Maoz <herouth@oumail.openu.ac.il>
1998-10-19 05:44 ` Peter T Mount <peter@retep.org.uk>
1998-10-19 08:13 ` Aleksey Demakov <avd@gcom.ru>
1998-10-19 17:15 ` Peter T Mount <peter@retep.org.uk>
2001-01-09 02:40 JDBC date problem Mike Cannon-Brookes <mike@bookmarkbox.com>
2001-01-09 22:53 JDBC date problem Mike Cannon-Brookes <mcannon@internet.com>
2001-01-10 09:42 ` Michael Stephenson <mstephenson@tirin.openworld.co.uk>
2001-01-10 13:19 ` Mike Cannon-Brookes <mcannon@internet.com>
2001-01-10 13:55 ` Mike Cannon-Brookes <mcannon@internet.com>
2001-01-12 04:31 ` Bruce Momjian <pgman@candle.pha.pa.us>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox