Обсуждение: Re: [INTERFACES] Trouble with JDBC2 ResultSet.getDate()

Поиск
Список
Период
Сортировка

Re: [INTERFACES] Trouble with JDBC2 ResultSet.getDate()

От
Barry Lind
Дата:
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


Re: Re: [INTERFACES] Trouble with JDBC2 ResultSet.getDate()

От
Juhan-Peep Ernits
Дата:

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




Re: Re: [INTERFACES] Trouble with JDBC2 ResultSet.getDate()

От
Peter T Mount
Дата:
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/