pg.ddx.io pgsql-interfaces@postgresql.org mailing list archive
help / color / mirror / Atom feedTrouble with JDBC2 ResultSet.getDate()
13+ messages / 5 participants
[nested] [flat]
* Trouble with JDBC2 ResultSet.getDate()
@ 2001-03-20 09:25 Juhan-Peep Ernits <juhan@cc.ioc.ee>
2001-03-20 17:57 ` Re: [INTERFACES] Trouble with JDBC2 ResultSet.getDate() Barry Lind <barry@xythos.com>
2001-05-08 14:16 ` Re: Trouble with JDBC2 ResultSet.getDate() Palle Girgensohn <girgen@partitur.se>
0 siblings, 2 replies; 13+ messages in thread
From: Juhan-Peep Ernits @ 2001-03-20 09:25 UTC (permalink / raw)
To: pgsql-interfaces; +Cc: pgsql-jdbc@postgresql.org
System is Debian "woody"
java is IBM SDK1.3
Source is CVS from March 20, 2001.
Trouble is the following, that
org.postgresql.jdbc2.ResultSet.getDate(int)
Started to generate errors
java.lang.NumberFormatException: 15 14:25:17+02
at java.lang.Integer.parseInt(Integer.java:415)
at java.lang.Integer.parseInt(Integer.java:455)
at java.sql.Date.valueOf(Date.java:97)
at org.postgresql.jdbc2.ResultSet.getDate(ResultSet.java:427)
at org.postgresql.jdbc2.ResultSet.getDate(ResultSet.java:665)
...
when fetching dates from fields of timestamp
type. It seems that the fixes provided in CVS version 1.18 from Jan 24
23:41:04 2001 of ResultSet.java regarding getDate() method broke it for
our application. Now I went back to 1.17 and copied the
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
try {
return new java.sql.Date(df.parse(s).getTime());
} catch (ParseException e) {
throw new PSQLException("postgresql.res.baddate",new
Integer(e.getErrorOffset()),s);
}
part to replace the new code:
return java.sql.Date.valueOf(s);
and it works fine but I have not had time to debug this any further. May
be it would be nice to have that part of the old code included in the 7.1
release driver?
Regards,
Juhan Ernits
^ permalink raw reply [nested|flat] 13+ messages in thread
* Re: [INTERFACES] Trouble with JDBC2 ResultSet.getDate()
2001-03-20 09:25 Trouble with JDBC2 ResultSet.getDate() Juhan-Peep Ernits <juhan@cc.ioc.ee>
@ 2001-03-20 17:57 ` Barry Lind <barry@xythos.com>
2001-03-21 09:11 ` Re: Re: [INTERFACES] Trouble with JDBC2 ResultSet.getDate() Peter T Mount <peter@retep.org.uk>
2001-03-21 09:29 ` Re: Re: [INTERFACES] Trouble with JDBC2 ResultSet.getDate() Juhan-Peep Ernits <juhan@cc.ioc.ee>
1 sibling, 2 replies; 13+ messages in thread
From: Barry Lind @ 2001-03-20 17:57 UTC (permalink / raw)
To: Juhan-Peep Ernits <juhan@cc.ioc.ee>; pgsql-jdbc@postgresql.org
Actually it was the changes in version 1.21 on 2/13 that broke this.
The cvs log for that change includes the following comment:
- Removed need for SimpleDateFormat in ResultSet.getDate() improving
performance.
My guess is the the code as written would work correctly for a 'date'
column, but doesn't work for a 'timestamp' column. Is there a reason
you are not using getTimestamp() to get the value of the timestamp column?
thanks,
--Barry
Juhan-Peep Ernits wrote:
> System is Debian "woody"
> java is IBM SDK1.3
> Source is CVS from March 20, 2001.
>
> Trouble is the following, that
>
> org.postgresql.jdbc2.ResultSet.getDate(int)
>
> Started to generate errors
>
> java.lang.NumberFormatException: 15 14:25:17+02
> at java.lang.Integer.parseInt(Integer.java:415)
> at java.lang.Integer.parseInt(Integer.java:455)
> at java.sql.Date.valueOf(Date.java:97)
> at org.postgresql.jdbc2.ResultSet.getDate(ResultSet.java:427)
> at org.postgresql.jdbc2.ResultSet.getDate(ResultSet.java:665)
> ....
>
> when fetching dates from fields of timestamp
> type. It seems that the fixes provided in CVS version 1.18 from Jan 24
> 23:41:04 2001 of ResultSet.java regarding getDate() method broke it for
> our application. Now I went back to 1.17 and copied the
>
> SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
>
> try {
> return new java.sql.Date(df.parse(s).getTime());
> } catch (ParseException e) {
> throw new PSQLException("postgresql.res.baddate",new
> Integer(e.getErrorOffset()),s);
> }
>
> part to replace the new code:
>
> return java.sql.Date.valueOf(s);
>
> and it works fine but I have not had time to debug this any further. May
> be it would be nice to have that part of the old code included in the 7.1
> release driver?
>
> Regards,
>
> Juhan Ernits
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://www.postgresql.org/search.mpl
^ permalink raw reply [nested|flat] 13+ messages in thread
* Re: Re: [INTERFACES] Trouble with JDBC2 ResultSet.getDate()
2001-03-20 09:25 Trouble with JDBC2 ResultSet.getDate() Juhan-Peep Ernits <juhan@cc.ioc.ee>
2001-03-20 17:57 ` Re: [INTERFACES] Trouble with JDBC2 ResultSet.getDate() Barry Lind <barry@xythos.com>
@ 2001-03-21 09:11 ` Peter T Mount <peter@retep.org.uk>
1 sibling, 0 replies; 13+ messages in thread
From: Peter T Mount @ 2001-03-21 09:11 UTC (permalink / raw)
To: Barry Lind <barry@xythos.com>; +Cc: Juhan-Peep Ernits <juhan@cc.ioc.ee>; pgsql-jdbc@postgresql.org
Quoting Barry Lind <barry@xythos.com>:
> Actually it was the changes in version 1.21 on 2/13 that broke this.
> The cvs log for that change includes the following comment:
> - Removed need for SimpleDateFormat in ResultSet.getDate() improving
> performance.
>
> My guess is the the code as written would work correctly for a 'date'
> column, but doesn't work for a 'timestamp' column. Is there a reason
> you are not using getTimestamp() to get the value of the timestamp
> column?
One of the first things I'm doing once 7.1 is out is add some sanity checking
so that the get/set methods on Date, Timestamp, integer, double etc so that
getDate() on a Timestamp would work, but also getTimestamp() on a Date column.
However, this isn't going to be that easy, and (when I thought of this) 7.1 was
already in beta - and this being new functionality couldn't be put in ;-)
Peter
--
Peter Mount peter@retep.org.uk
PostgreSQL JDBC Driver: http://www.retep.org.uk/postgres/
RetepPDF PDF library for Java: http://www.retep.org.uk/pdf/
^ permalink raw reply [nested|flat] 13+ messages in thread
* Re: Re: [INTERFACES] Trouble with JDBC2 ResultSet.getDate()
2001-03-20 09:25 Trouble with JDBC2 ResultSet.getDate() Juhan-Peep Ernits <juhan@cc.ioc.ee>
2001-03-20 17:57 ` Re: [INTERFACES] Trouble with JDBC2 ResultSet.getDate() Barry Lind <barry@xythos.com>
@ 2001-03-21 09:29 ` Juhan-Peep Ernits <juhan@cc.ioc.ee>
1 sibling, 0 replies; 13+ messages in thread
From: Juhan-Peep Ernits @ 2001-03-21 09:29 UTC (permalink / raw)
To: Barry Lind <barry@xythos.com>; +Cc: pgsql-jdbc@postgresql.org
On Tue, 20 Mar 2001, Barry Lind wrote:
> Actually it was the changes in version 1.21 on 2/13 that broke this.
> The cvs log for that change includes the following comment:
> - Removed need for SimpleDateFormat in ResultSet.getDate() improving
> performance.
Yes, of course. My mistake.
> My guess is the the code as written would work correctly for a 'date'
> column, but doesn't work for a 'timestamp' column. Is there a reason
> you are not using getTimestamp() to get the value of the timestamp column?
The reason is that the code contains getDate() because it used to work and
we need to print it in date format. The Java SDK1.3 api description does
just say, that it
gets the value of the designated column in the current row
of this ResultSet object as a java.sql.Date object in the Java programming language.
It does not imply that the underlying column cannot be of Timestamp type,
since e.g. getString() works fine on numeric etc.
I do not know how many people have similar issues, but less performance
for more robustness would be my call in this case (i.e. rollback to
earlier version).
But if other people do not experience those problems I'll look forward to
the modifications that Peter T Mount mentioned:
("One of the first things I'm doing once 7.1 is out is add some sanity
checking so that the get/set methods on Date, Timestamp, integer, double
etc so that getDate() on a Timestamp would work, but also
getTimestamp() on a Date column.")
and have a workaround for the mean time.
Regards,
Juhan Ernits
^ permalink raw reply [nested|flat] 13+ messages in thread
* Re: Trouble with JDBC2 ResultSet.getDate()
2001-03-20 09:25 Trouble with JDBC2 ResultSet.getDate() Juhan-Peep Ernits <juhan@cc.ioc.ee>
@ 2001-05-08 14:16 ` Palle Girgensohn <girgen@partitur.se>
2001-05-08 15:20 ` Re: [JDBC] Re: Trouble with JDBC2 ResultSet.getDate() Juhan-Peep Ernits <juhan@cc.ioc.ee>
2001-05-08 16:28 ` Re: [JDBC] Re: Trouble with JDBC2 ResultSet.getDate() Palle Girgensohn <girgen@partitur.se>
2001-05-08 17:29 ` Re: [JDBC] Re: Trouble with JDBC2 ResultSet.getDate() Bruce Momjian <pgman@candle.pha.pa.us>
2001-05-30 16:34 ` Re: [JDBC] Re: Trouble with JDBC2 ResultSet.getDate() Bruce Momjian <pgman@candle.pha.pa.us>
1 sibling, 4 replies; 13+ messages in thread
From: Palle Girgensohn @ 2001-05-08 14:16 UTC (permalink / raw)
To: Juhan-Peep Ernits <juhan@cc.ioc.ee>; +Cc: pgsql-interfaces; pgsql-jdbc@postgresql.org; peter@retep.org.uk
Hi!
I just got bitten by this too. I use type timestamp in the
database, and often need the latest timestamp, but want to
format it as a date. With 7.0.x, I just
select ts from foo order by ts desc limit 1
and in java: d = res.getDate(1);
but this fails everywhere in my code now :(
The problem is this optimization in
src/interfaces/jdbc/org/postgresql/jdbc2/ResultSet.java,
introduced in 1.21:
@@ -418,12 +418,8 @@
String s = getString(columnIndex);
if(s==null)
return null;
- SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
- try {
- return new java.sql.Date(df.parse(s).getTime());
- } catch (ParseException e) {
- throw new PSQLException("postgresql.res.baddate",new
Integer(e.getErrorOffset()),s);
- }
+
+ return java.sql.Date.valueOf(s);
}
/**
Log string is:
- Removed need for SimpleDateFormat in ResultSet.getDate()
improving performance.
I cannot find any reference to whether it is bad or not to let
getDate return a date when the string from postgres is a
timestamp or datetime. It appears to me as a good feature, and
since it has been working for quite som time, and the postgres
documenation recommends timestamp as the best time & date type,
is it really necessary to break functionality for many users
this way? The performance fix is good, but I think code shall
be added to make it backward compatible.
My query will need to be rewritten like this:
select ts::date as d, ts from foo order by ts desc limit 1
and I have hundreds of them :(
Maybe we can introduce a try-catch clause to handle the case
where the string is really a timestamp and not a pure date, but
this would give users the false impression that everything is
OK, and exceptions are really a performance hog... Maybe just
check if the string size is > 10, and then use the old code?
Agree, this would make it complicated.
/Palle
Juhan-Peep Ernits wrote:
>
> System is Debian "woody"
> java is IBM SDK1.3
> Source is CVS from March 20, 2001.
>
> Trouble is the following, that
>
> org.postgresql.jdbc2.ResultSet.getDate(int)
>
> Started to generate errors
>
> java.lang.NumberFormatException: 15 14:25:17+02
> at java.lang.Integer.parseInt(Integer.java:415)
> at java.lang.Integer.parseInt(Integer.java:455)
> at java.sql.Date.valueOf(Date.java:97)
> at org.postgresql.jdbc2.ResultSet.getDate(ResultSet.java:427)
> at org.postgresql.jdbc2.ResultSet.getDate(ResultSet.java:665)
> ...
>
> when fetching dates from fields of timestamp
> type. It seems that the fixes provided in CVS version 1.18 from Jan 24
> 23:41:04 2001 of ResultSet.java regarding getDate() method broke it for
> our application. Now I went back to 1.17 and copied the
>
> SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
>
> try {
> return new java.sql.Date(df.parse(s).getTime());
> } catch (ParseException e) {
> throw new PSQLException("postgresql.res.baddate",new
> Integer(e.getErrorOffset()),s);
> }
>
> part to replace the new code:
>
> return java.sql.Date.valueOf(s);
>
> and it works fine but I have not had time to debug this any further. May
> be it would be nice to have that part of the old code included in the 7.1
> release driver?
>
> Regards,
>
> Juhan Ernits
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://www.postgresql.org/search.mpl
--
Partitur Informationsteknik AB
Wenner-Gren Center +46 8 566 280 02
113 46 Stockholm +46 70 785 86 02
Sweden girgen@partitur.se
^ permalink raw reply [nested|flat] 13+ messages in thread
* Re: [JDBC] Re: Trouble with JDBC2 ResultSet.getDate()
2001-03-20 09:25 Trouble with JDBC2 ResultSet.getDate() Juhan-Peep Ernits <juhan@cc.ioc.ee>
2001-05-08 14:16 ` Re: Trouble with JDBC2 ResultSet.getDate() Palle Girgensohn <girgen@partitur.se>
@ 2001-05-08 15:20 ` Juhan-Peep Ernits <juhan@cc.ioc.ee>
2001-05-08 16:34 ` Re: [JDBC] Re: Trouble with JDBC2 ResultSet.getDate() Bruce Momjian <pgman@candle.pha.pa.us>
3 siblings, 1 reply; 13+ messages in thread
From: Juhan-Peep Ernits @ 2001-05-08 15:20 UTC (permalink / raw)
To: Palle Girgensohn <girgen@partitur.se>; +Cc: pgsql-interfaces; pgsql-jdbc@postgresql.org
Hello!
We solved the problem by patching the code of the jdbc driver (since the
new code has ResultSet.getStatement() method and other useful
enhancements) for some time, while we changed the code to use
getTimestamp() method, since it is not a good idea to stick to patching
the code of the jdbc driver.
Of course it would be more comfortable if one could use getDate on a
timestamp field, but it is not by default always available.
In our case the new approach lead to more robust code (more typesafe),
and in addition there were also a few other things that resolved when we
started to use the new driver, so eventually we benefitted a lot of it. It
depends how much code you have to rewrite but I'd suggest doing that.
Juhan Ernits
On Tue, 8 May 2001, Palle Girgensohn wrote:
> I just got bitten by this too. I use type timestamp in the
> database, and often need the latest timestamp, but want to
> format it as a date. With 7.0.x, I just
>
> select ts from foo order by ts desc limit 1
>
> and in java: d = res.getDate(1);
>
> but this fails everywhere in my code now :(
^ permalink raw reply [nested|flat] 13+ messages in thread
* Re: [JDBC] Re: Trouble with JDBC2 ResultSet.getDate()
2001-03-20 09:25 Trouble with JDBC2 ResultSet.getDate() Juhan-Peep Ernits <juhan@cc.ioc.ee>
2001-05-08 14:16 ` Re: Trouble with JDBC2 ResultSet.getDate() Palle Girgensohn <girgen@partitur.se>
2001-05-08 15:20 ` Re: [JDBC] Re: Trouble with JDBC2 ResultSet.getDate() Juhan-Peep Ernits <juhan@cc.ioc.ee>
@ 2001-05-08 16:34 ` Bruce Momjian <pgman@candle.pha.pa.us>
2001-05-08 16:43 ` Re: [JDBC] Re: Trouble with JDBC2 ResultSet.getDate() Palle Girgensohn <girgen@partitur.se>
0 siblings, 1 reply; 13+ messages in thread
From: Bruce Momjian @ 2001-05-08 16:34 UTC (permalink / raw)
To: Juhan-Peep Ernits <juhan@cc.ioc.ee>; +Cc: Palle Girgensohn <girgen@partitur.se>; pgsql-interfaces; pgsql-jdbc@postgresql.org
So, I am concluding that the timestamp patch should not be applied the
jdbc tree.
>
> Hello!
>
> We solved the problem by patching the code of the jdbc driver (since the
> new code has ResultSet.getStatement() method and other useful
> enhancements) for some time, while we changed the code to use
> getTimestamp() method, since it is not a good idea to stick to patching
> the code of the jdbc driver.
>
> Of course it would be more comfortable if one could use getDate on a
> timestamp field, but it is not by default always available.
>
> In our case the new approach lead to more robust code (more typesafe),
> and in addition there were also a few other things that resolved when we
> started to use the new driver, so eventually we benefitted a lot of it. It
> depends how much code you have to rewrite but I'd suggest doing that.
>
> Juhan Ernits
>
>
>
>
> On Tue, 8 May 2001, Palle Girgensohn wrote:
>
> > I just got bitten by this too. I use type timestamp in the
> > database, and often need the latest timestamp, but want to
> > format it as a date. With 7.0.x, I just
> >
> > select ts from foo order by ts desc limit 1
> >
> > and in java: d = res.getDate(1);
> >
> > but this fails everywhere in my code now :(
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo@postgresql.org so that your
> message can get through to the mailing list cleanly
>
--
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] 13+ messages in thread
* Re: [JDBC] Re: Trouble with JDBC2 ResultSet.getDate()
2001-03-20 09:25 Trouble with JDBC2 ResultSet.getDate() Juhan-Peep Ernits <juhan@cc.ioc.ee>
2001-05-08 14:16 ` Re: Trouble with JDBC2 ResultSet.getDate() Palle Girgensohn <girgen@partitur.se>
2001-05-08 15:20 ` Re: [JDBC] Re: Trouble with JDBC2 ResultSet.getDate() Juhan-Peep Ernits <juhan@cc.ioc.ee>
2001-05-08 16:34 ` Re: [JDBC] Re: Trouble with JDBC2 ResultSet.getDate() Bruce Momjian <pgman@candle.pha.pa.us>
@ 2001-05-08 16:43 ` Palle Girgensohn <girgen@partitur.se>
2001-05-08 16:44 ` Re: [JDBC] Re: Trouble with JDBC2 ResultSet.getDate() Bruce Momjian <pgman@candle.pha.pa.us>
0 siblings, 1 reply; 13+ messages in thread
From: Palle Girgensohn @ 2001-05-08 16:43 UTC (permalink / raw)
To: Bruce Momjian <pgman@candle.pha.pa.us>; +Cc: Juhan-Peep Ernits <juhan@cc.ioc.ee>; pgsql-interfaces; pgsql-jdbc@postgresql.org
Well, I didn't see the patch, but my message (probably you just
received) points to the fact that getDate shall work on a
timestamp column, and some kind of patch shall be applied. I
something like this:
if s.length() == 10
return java.sql.Date.valueOf(s)
else do the old 7.0.3 SimpleDateFormatter stuff.
*or*
try {
return java.sql.Date.valueOf(s)
} catch (SQLException e) {
do the old SimpleDateFormatter stuff...
}
sort of... gotta go, or I'd have sent you a full patch.
/Palle
Bruce Momjian wrote:
>
> So, I am concluding that the timestamp patch should not be applied the
> jdbc tree.
>
> >
> > Hello!
> >
> > We solved the problem by patching the code of the jdbc driver (since the
> > new code has ResultSet.getStatement() method and other useful
> > enhancements) for some time, while we changed the code to use
> > getTimestamp() method, since it is not a good idea to stick to patching
> > the code of the jdbc driver.
> >
> > Of course it would be more comfortable if one could use getDate on a
> > timestamp field, but it is not by default always available.
> >
> > In our case the new approach lead to more robust code (more typesafe),
> > and in addition there were also a few other things that resolved when we
> > started to use the new driver, so eventually we benefitted a lot of it. It
> > depends how much code you have to rewrite but I'd suggest doing that.
> >
> > Juhan Ernits
> >
> >
> >
> >
> > On Tue, 8 May 2001, Palle Girgensohn wrote:
> >
> > > I just got bitten by this too. I use type timestamp in the
> > > database, and often need the latest timestamp, but want to
> > > format it as a date. With 7.0.x, I just
> > >
> > > select ts from foo order by ts desc limit 1
> > >
> > > and in java: d = res.getDate(1);
> > >
> > > but this fails everywhere in my code now :(
> >
> >
> > ---------------------------(end of broadcast)---------------------------
> > TIP 3: if posting/reading through Usenet, please send an appropriate
> > subscribe-nomail command to majordomo@postgresql.org so that your
> > message can get through to the mailing list cleanly
> >
>
> --
> 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
--
Partitur Informationsteknik AB
Wenner-Gren Center +46 8 566 280 02
113 46 Stockholm +46 70 785 86 02
Sweden girgen@partitur.se
^ permalink raw reply [nested|flat] 13+ messages in thread
* Re: [JDBC] Re: Trouble with JDBC2 ResultSet.getDate()
2001-03-20 09:25 Trouble with JDBC2 ResultSet.getDate() Juhan-Peep Ernits <juhan@cc.ioc.ee>
2001-05-08 14:16 ` Re: Trouble with JDBC2 ResultSet.getDate() Palle Girgensohn <girgen@partitur.se>
2001-05-08 15:20 ` Re: [JDBC] Re: Trouble with JDBC2 ResultSet.getDate() Juhan-Peep Ernits <juhan@cc.ioc.ee>
2001-05-08 16:34 ` Re: [JDBC] Re: Trouble with JDBC2 ResultSet.getDate() Bruce Momjian <pgman@candle.pha.pa.us>
2001-05-08 16:43 ` Re: [JDBC] Re: Trouble with JDBC2 ResultSet.getDate() Palle Girgensohn <girgen@partitur.se>
@ 2001-05-08 16:44 ` Bruce Momjian <pgman@candle.pha.pa.us>
2001-05-09 02:45 ` Re: [JDBC] Re: Trouble with JDBC2 ResultSet.getDate() Palle Girgensohn <girgen@partitur.se>
0 siblings, 1 reply; 13+ messages in thread
From: Bruce Momjian @ 2001-05-08 16:44 UTC (permalink / raw)
To: Palle Girgensohn <girgen@partitur.se>; +Cc: Juhan-Peep Ernits <juhan@cc.ioc.ee>; pgsql-interfaces; pgsql-jdbc@postgresql.org
> Well, I didn't see the patch, but my message (probably you just
> received) points to the fact that getDate shall work on a
> timestamp column, and some kind of patch shall be applied. I
> something like this:
>
> if s.length() == 10
> return java.sql.Date.valueOf(s)
> else do the old 7.0.3 SimpleDateFormatter stuff.
>
> *or*
>
> try {
> return java.sql.Date.valueOf(s)
> } catch (SQLException e) {
> do the old SimpleDateFormatter stuff...
> }
>
> sort of... gotta go, or I'd have sent you a full patch.
Would you, please? Thanks.
--
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] 13+ messages in thread
* Re: [JDBC] Re: Trouble with JDBC2 ResultSet.getDate()
2001-03-20 09:25 Trouble with JDBC2 ResultSet.getDate() Juhan-Peep Ernits <juhan@cc.ioc.ee>
2001-05-08 14:16 ` Re: Trouble with JDBC2 ResultSet.getDate() Palle Girgensohn <girgen@partitur.se>
2001-05-08 15:20 ` Re: [JDBC] Re: Trouble with JDBC2 ResultSet.getDate() Juhan-Peep Ernits <juhan@cc.ioc.ee>
2001-05-08 16:34 ` Re: [JDBC] Re: Trouble with JDBC2 ResultSet.getDate() Bruce Momjian <pgman@candle.pha.pa.us>
2001-05-08 16:43 ` Re: [JDBC] Re: Trouble with JDBC2 ResultSet.getDate() Palle Girgensohn <girgen@partitur.se>
2001-05-08 16:44 ` Re: [JDBC] Re: Trouble with JDBC2 ResultSet.getDate() Bruce Momjian <pgman@candle.pha.pa.us>
@ 2001-05-09 02:45 ` Palle Girgensohn <girgen@partitur.se>
0 siblings, 0 replies; 13+ messages in thread
From: Palle Girgensohn @ 2001-05-09 02:45 UTC (permalink / raw)
To: Bruce Momjian <pgman@candle.pha.pa.us>; +Cc: Juhan-Peep Ernits <juhan@cc.ioc.ee>; pgsql-interfaces; pgsql-jdbc@postgresql.org
Here's a patch that works fine for me.
Cheers,
Palle
Bruce Momjian wrote:
>
> > Well, I didn't see the patch, but my message (probably you just
> > received) points to the fact that getDate shall work on a
> > timestamp column, and some kind of patch shall be applied. I
> > something like this:
> >
> > if s.length() == 10
> > return java.sql.Date.valueOf(s)
> > else do the old 7.0.3 SimpleDateFormatter stuff.
> >
> > *or*
> >
> > try {
> > return java.sql.Date.valueOf(s)
> > } catch (SQLException e) {
> > do the old SimpleDateFormatter stuff...
> > }
> >
> > sort of... gotta go, or I'd have sent you a full patch.
>
> Would you, please? Thanks.
>
> --
> 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
Attachments:
patch-jdbc-getdate (application/octet-stream, 1007B) download
^ permalink raw reply [nested|flat] 13+ messages in thread
* Re: [JDBC] Re: Trouble with JDBC2 ResultSet.getDate()
2001-03-20 09:25 Trouble with JDBC2 ResultSet.getDate() Juhan-Peep Ernits <juhan@cc.ioc.ee>
2001-05-08 14:16 ` Re: Trouble with JDBC2 ResultSet.getDate() Palle Girgensohn <girgen@partitur.se>
@ 2001-05-08 16:28 ` Palle Girgensohn <girgen@partitur.se>
3 siblings, 0 replies; 13+ messages in thread
From: Palle Girgensohn @ 2001-05-08 16:28 UTC (permalink / raw)
To: Juhan-Peep Ernits <juhan@cc.ioc.ee>; pgsql-interfaces; pgsql-jdbc@postgresql.org; peter@retep.org.uk
Well,
http://java.sun.com/j2se/1.3/docs/guide/jdbc/spec/jdbc-spec.frame7.html
says
The ResultSet.getXXX methods will attempt to
convert whatever SQL type was returned by the
database to whatever Java type is returned by
the getXXX method.
and there is a table that clearly shows that getDate shall eat
timestamp and return a proper date. Hence, I consider this to
be a bug in the new code.
/Palle
Palle Girgensohn wrote:
>
> Hi!
>
> I just got bitten by this too. I use type timestamp in the
> database, and often need the latest timestamp, but want to
> format it as a date. With 7.0.x, I just
>
> select ts from foo order by ts desc limit 1
>
> and in java: d = res.getDate(1);
>
> but this fails everywhere in my code now :(
>
> The problem is this optimization in
> src/interfaces/jdbc/org/postgresql/jdbc2/ResultSet.java,
> introduced in 1.21:
>
> @@ -418,12 +418,8 @@
> String s = getString(columnIndex);
> if(s==null)
> return null;
> - SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
> - try {
> - return new java.sql.Date(df.parse(s).getTime());
> - } catch (ParseException e) {
> - throw new PSQLException("postgresql.res.baddate",new
> Integer(e.getErrorOffset()),s);
> - }
> +
> + return java.sql.Date.valueOf(s);
> }
>
> /**
>
> Log string is:
>
> - Removed need for SimpleDateFormat in ResultSet.getDate()
> improving performance.
>
> I cannot find any reference to whether it is bad or not to let
> getDate return a date when the string from postgres is a
> timestamp or datetime. It appears to me as a good feature, and
> since it has been working for quite som time, and the postgres
> documenation recommends timestamp as the best time & date type,
> is it really necessary to break functionality for many users
> this way? The performance fix is good, but I think code shall
> be added to make it backward compatible.
>
> My query will need to be rewritten like this:
>
> select ts::date as d, ts from foo order by ts desc limit 1
>
> and I have hundreds of them :(
>
> Maybe we can introduce a try-catch clause to handle the case
> where the string is really a timestamp and not a pure date, but
> this would give users the false impression that everything is
> OK, and exceptions are really a performance hog... Maybe just
> check if the string size is > 10, and then use the old code?
> Agree, this would make it complicated.
>
> /Palle
>
> Juhan-Peep Ernits wrote:
> >
> > System is Debian "woody"
> > java is IBM SDK1.3
> > Source is CVS from March 20, 2001.
> >
> > Trouble is the following, that
> >
> > org.postgresql.jdbc2.ResultSet.getDate(int)
> >
> > Started to generate errors
> >
> > java.lang.NumberFormatException: 15 14:25:17+02
> > at java.lang.Integer.parseInt(Integer.java:415)
> > at java.lang.Integer.parseInt(Integer.java:455)
> > at java.sql.Date.valueOf(Date.java:97)
> > at org.postgresql.jdbc2.ResultSet.getDate(ResultSet.java:427)
> > at org.postgresql.jdbc2.ResultSet.getDate(ResultSet.java:665)
> > ...
> >
> > when fetching dates from fields of timestamp
> > type. It seems that the fixes provided in CVS version 1.18 from Jan 24
> > 23:41:04 2001 of ResultSet.java regarding getDate() method broke it for
> > our application. Now I went back to 1.17 and copied the
> >
> > SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
> >
> > try {
> > return new java.sql.Date(df.parse(s).getTime());
> > } catch (ParseException e) {
> > throw new PSQLException("postgresql.res.baddate",new
> > Integer(e.getErrorOffset()),s);
> > }
> >
> > part to replace the new code:
> >
> > return java.sql.Date.valueOf(s);
> >
> > and it works fine but I have not had time to debug this any further. May
> > be it would be nice to have that part of the old code included in the 7.1
> > release driver?
> >
> > Regards,
> >
> > Juhan Ernits
> >
> > ---------------------------(end of broadcast)---------------------------
> > TIP 6: Have you searched our list archives?
> >
> > http://www.postgresql.org/search.mpl
>
> --
> Partitur Informationsteknik AB
> Wenner-Gren Center +46 8 566 280 02
> 113 46 Stockholm +46 70 785 86 02
> Sweden girgen@partitur.se
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo@postgresql.org so that your
> message can get through to the mailing list cleanly
--
Partitur Informationsteknik AB
Wenner-Gren Center +46 8 566 280 02
113 46 Stockholm +46 70 785 86 02
Sweden girgen@partitur.se
^ permalink raw reply [nested|flat] 13+ messages in thread
* Re: [JDBC] Re: Trouble with JDBC2 ResultSet.getDate()
2001-03-20 09:25 Trouble with JDBC2 ResultSet.getDate() Juhan-Peep Ernits <juhan@cc.ioc.ee>
2001-05-08 14:16 ` Re: Trouble with JDBC2 ResultSet.getDate() Palle Girgensohn <girgen@partitur.se>
@ 2001-05-08 17:29 ` Bruce Momjian <pgman@candle.pha.pa.us>
3 siblings, 0 replies; 13+ messages in thread
From: Bruce Momjian @ 2001-05-08 17:29 UTC (permalink / raw)
To: Palle Girgensohn <girgen@partitur.se>; +Cc: Juhan-Peep Ernits <juhan@cc.ioc.ee>; pgsql-interfaces; pgsql-jdbc@postgresql.org; peter@retep.org.uk
Is this the patch you are suggesting be applied?
> Hi!
>
> I just got bitten by this too. I use type timestamp in the
> database, and often need the latest timestamp, but want to
> format it as a date. With 7.0.x, I just
>
> select ts from foo order by ts desc limit 1
>
> and in java: d = res.getDate(1);
>
> but this fails everywhere in my code now :(
>
> The problem is this optimization in
> src/interfaces/jdbc/org/postgresql/jdbc2/ResultSet.java,
> introduced in 1.21:
>
> @@ -418,12 +418,8 @@
> String s = getString(columnIndex);
> if(s==null)
> return null;
> - SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
> - try {
> - return new java.sql.Date(df.parse(s).getTime());
> - } catch (ParseException e) {
> - throw new PSQLException("postgresql.res.baddate",new
> Integer(e.getErrorOffset()),s);
> - }
> +
> + return java.sql.Date.valueOf(s);
> }
>
> /**
>
>
> Log string is:
>
> - Removed need for SimpleDateFormat in ResultSet.getDate()
> improving performance.
>
> I cannot find any reference to whether it is bad or not to let
> getDate return a date when the string from postgres is a
> timestamp or datetime. It appears to me as a good feature, and
> since it has been working for quite som time, and the postgres
> documenation recommends timestamp as the best time & date type,
> is it really necessary to break functionality for many users
> this way? The performance fix is good, but I think code shall
> be added to make it backward compatible.
>
> My query will need to be rewritten like this:
>
> select ts::date as d, ts from foo order by ts desc limit 1
>
> and I have hundreds of them :(
>
> Maybe we can introduce a try-catch clause to handle the case
> where the string is really a timestamp and not a pure date, but
> this would give users the false impression that everything is
> OK, and exceptions are really a performance hog... Maybe just
> check if the string size is > 10, and then use the old code?
> Agree, this would make it complicated.
>
> /Palle
>
>
> Juhan-Peep Ernits wrote:
> >
> > System is Debian "woody"
> > java is IBM SDK1.3
> > Source is CVS from March 20, 2001.
> >
> > Trouble is the following, that
> >
> > org.postgresql.jdbc2.ResultSet.getDate(int)
> >
> > Started to generate errors
> >
> > java.lang.NumberFormatException: 15 14:25:17+02
> > at java.lang.Integer.parseInt(Integer.java:415)
> > at java.lang.Integer.parseInt(Integer.java:455)
> > at java.sql.Date.valueOf(Date.java:97)
> > at org.postgresql.jdbc2.ResultSet.getDate(ResultSet.java:427)
> > at org.postgresql.jdbc2.ResultSet.getDate(ResultSet.java:665)
> > ...
> >
> > when fetching dates from fields of timestamp
> > type. It seems that the fixes provided in CVS version 1.18 from Jan 24
> > 23:41:04 2001 of ResultSet.java regarding getDate() method broke it for
> > our application. Now I went back to 1.17 and copied the
> >
> > SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
> >
> > try {
> > return new java.sql.Date(df.parse(s).getTime());
> > } catch (ParseException e) {
> > throw new PSQLException("postgresql.res.baddate",new
> > Integer(e.getErrorOffset()),s);
> > }
> >
> > part to replace the new code:
> >
> > return java.sql.Date.valueOf(s);
> >
> > and it works fine but I have not had time to debug this any further. May
> > be it would be nice to have that part of the old code included in the 7.1
> > release driver?
> >
> > Regards,
> >
> > Juhan Ernits
> >
> > ---------------------------(end of broadcast)---------------------------
> > TIP 6: Have you searched our list archives?
> >
> > http://www.postgresql.org/search.mpl
>
> --
> Partitur Informationsteknik AB
> Wenner-Gren Center +46 8 566 280 02
> 113 46 Stockholm +46 70 785 86 02
> Sweden girgen@partitur.se
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo@postgresql.org so that your
> message can get through to the mailing list cleanly
>
--
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] 13+ messages in thread
* Re: [JDBC] Re: Trouble with JDBC2 ResultSet.getDate()
2001-03-20 09:25 Trouble with JDBC2 ResultSet.getDate() Juhan-Peep Ernits <juhan@cc.ioc.ee>
2001-05-08 14:16 ` Re: Trouble with JDBC2 ResultSet.getDate() Palle Girgensohn <girgen@partitur.se>
@ 2001-05-30 16:34 ` Bruce Momjian <pgman@candle.pha.pa.us>
3 siblings, 0 replies; 13+ messages in thread
From: Bruce Momjian @ 2001-05-30 16:34 UTC (permalink / raw)
To: Palle Girgensohn <girgen@partitur.se>; +Cc: Juhan-Peep Ernits <juhan@cc.ioc.ee>; pgsql-interfaces; pgsql-jdbc@postgresql.org; peter@retep.org.uk
Patch applied. Standards require it. If Peter adds casting later, this
can be removed. We are clearly seeing problem reports about this.
Thanks.
> Hi!
>
> I just got bitten by this too. I use type timestamp in the
> database, and often need the latest timestamp, but want to
> format it as a date. With 7.0.x, I just
>
> select ts from foo order by ts desc limit 1
>
> and in java: d = res.getDate(1);
>
> but this fails everywhere in my code now :(
>
> The problem is this optimization in
> src/interfaces/jdbc/org/postgresql/jdbc2/ResultSet.java,
> introduced in 1.21:
>
> @@ -418,12 +418,8 @@
> String s = getString(columnIndex);
> if(s==null)
> return null;
> - SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
> - try {
> - return new java.sql.Date(df.parse(s).getTime());
> - } catch (ParseException e) {
> - throw new PSQLException("postgresql.res.baddate",new
> Integer(e.getErrorOffset()),s);
> - }
> +
> + return java.sql.Date.valueOf(s);
> }
>
> /**
>
>
> Log string is:
>
> - Removed need for SimpleDateFormat in ResultSet.getDate()
> improving performance.
>
> I cannot find any reference to whether it is bad or not to let
> getDate return a date when the string from postgres is a
> timestamp or datetime. It appears to me as a good feature, and
> since it has been working for quite som time, and the postgres
> documenation recommends timestamp as the best time & date type,
> is it really necessary to break functionality for many users
> this way? The performance fix is good, but I think code shall
> be added to make it backward compatible.
>
> My query will need to be rewritten like this:
>
> select ts::date as d, ts from foo order by ts desc limit 1
>
> and I have hundreds of them :(
>
> Maybe we can introduce a try-catch clause to handle the case
> where the string is really a timestamp and not a pure date, but
> this would give users the false impression that everything is
> OK, and exceptions are really a performance hog... Maybe just
> check if the string size is > 10, and then use the old code?
> Agree, this would make it complicated.
>
> /Palle
>
>
> Juhan-Peep Ernits wrote:
> >
> > System is Debian "woody"
> > java is IBM SDK1.3
> > Source is CVS from March 20, 2001.
> >
> > Trouble is the following, that
> >
> > org.postgresql.jdbc2.ResultSet.getDate(int)
> >
> > Started to generate errors
> >
> > java.lang.NumberFormatException: 15 14:25:17+02
> > at java.lang.Integer.parseInt(Integer.java:415)
> > at java.lang.Integer.parseInt(Integer.java:455)
> > at java.sql.Date.valueOf(Date.java:97)
> > at org.postgresql.jdbc2.ResultSet.getDate(ResultSet.java:427)
> > at org.postgresql.jdbc2.ResultSet.getDate(ResultSet.java:665)
> > ...
> >
> > when fetching dates from fields of timestamp
> > type. It seems that the fixes provided in CVS version 1.18 from Jan 24
> > 23:41:04 2001 of ResultSet.java regarding getDate() method broke it for
> > our application. Now I went back to 1.17 and copied the
> >
> > SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
> >
> > try {
> > return new java.sql.Date(df.parse(s).getTime());
> > } catch (ParseException e) {
> > throw new PSQLException("postgresql.res.baddate",new
> > Integer(e.getErrorOffset()),s);
> > }
> >
> > part to replace the new code:
> >
> > return java.sql.Date.valueOf(s);
> >
> > and it works fine but I have not had time to debug this any further. May
> > be it would be nice to have that part of the old code included in the 7.1
> > release driver?
> >
> > Regards,
> >
> > Juhan Ernits
> >
> > ---------------------------(end of broadcast)---------------------------
> > TIP 6: Have you searched our list archives?
> >
> > http://www.postgresql.org/search.mpl
>
> --
> Partitur Informationsteknik AB
> Wenner-Gren Center +46 8 566 280 02
> 113 46 Stockholm +46 70 785 86 02
> Sweden girgen@partitur.se
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo@postgresql.org so that your
> message can get through to the mailing list cleanly
>
--
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
Attachments:
/bjm/diff (text/plain, 1006B) download
--- src/interfaces/jdbc/org/postgresql/jdbc1/ResultSet.java~ Fri Feb 23 19:12:23 2001
+++ src/interfaces/jdbc/org/postgresql/jdbc1/ResultSet.java Wed May 9 04:31:11 2001
@@ -423,8 +423,13 @@
String s = getString(columnIndex);
if(s==null)
return null;
-
- return java.sql.Date.valueOf(s);
+ // length == 10: SQL Date
+ // length > 10: SQL Timestamp, assumes PGDATESTYLE=ISO
+ try {
+ return java.sql.Date.valueOf((s.length() == 10) ? s : s.substring(0,10));
+ } catch (NumberFormatException e) {
+ throw new PSQLException("postgresql.res.baddate", s);
+ }
}
/**
@@ -441,8 +446,13 @@
if(s==null)
return null; // SQL NULL
-
- return java.sql.Time.valueOf(s);
+ // length == 8: SQL Time
+ // length > 8: SQL Timestamp
+ try {
+ return java.sql.Time.valueOf((s.length() == 8) ? s : s.substring(11,19));
+ } catch (NumberFormatException e) {
+ throw new PSQLException("postgresql.res.badtime",s);
+ }
}
/**
^ permalink raw reply [nested|flat] 13+ messages in thread
end of thread, other threads:[~2001-05-30 16:34 UTC | newest]
Thread overview: 13+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-03-20 09:25 Trouble with JDBC2 ResultSet.getDate() Juhan-Peep Ernits <juhan@cc.ioc.ee>
2001-03-20 17:57 ` Barry Lind <barry@xythos.com>
2001-03-21 09:11 ` Peter T Mount <peter@retep.org.uk>
2001-03-21 09:29 ` Juhan-Peep Ernits <juhan@cc.ioc.ee>
2001-05-08 14:16 ` Palle Girgensohn <girgen@partitur.se>
2001-05-08 15:20 ` Juhan-Peep Ernits <juhan@cc.ioc.ee>
2001-05-08 16:34 ` Bruce Momjian <pgman@candle.pha.pa.us>
2001-05-08 16:43 ` Palle Girgensohn <girgen@partitur.se>
2001-05-08 16:44 ` Bruce Momjian <pgman@candle.pha.pa.us>
2001-05-09 02:45 ` Palle Girgensohn <girgen@partitur.se>
2001-05-08 16:28 ` Palle Girgensohn <girgen@partitur.se>
2001-05-08 17:29 ` Bruce Momjian <pgman@candle.pha.pa.us>
2001-05-30 16:34 ` 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