BUG #1177: JDBC driver doesn't handle all dates correctly

From: "PostgreSQL Bugs List" <pgsql-bugs(at)postgresql(dot)org>
To: pgsql-bugs(at)postgresql(dot)org
Subject: BUG #1177: JDBC driver doesn't handle all dates correctly
Date: 2004-06-22 12:14:15
Message-ID: 20040622121415.907C9CF49E0@www.postgresql.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs


The following bug has been logged online:

Bug reference: 1177
Logged by: Jan Normann Nielsen

Email address: spam(at)dubbekarl(dot)dk

PostgreSQL version: 7.4

Operating system: Linux (Insignificant)

Description: JDBC driver doesn't handle all dates correctly

Details:

In AbstractJdbc1Statement.setDate(int parameterIndex, java.sql.Date x), the
date 'x' is converted to a string by using x.toString() before being sent as
a parameter to a SQL-query, i.e. an INSERT-statement. The JavaDocs specify
that the result of this this toString method is the same as

new java.text.SimpleDateFormat("yyyy-MM-dd").format(x)

which, according to the documentation for SimpleDateFormat, will zero-pad
the year if it is less than four digits. This can happen if a very strange
date is chosen, which this case shows:

java.sql.Date x = new java.sql.Date(Long.MAX_VALUE);
System.out.println((int) x.toString().charAt(0));

This code will print '0'. Since x.toString() contains a null character, the
JDBC driver fails to send it as part of a query to the database by throwing:

java.sql.SQLException: ERROR: Unterminated quoted string
at
org.postgresql.core.QueryExecutor.executeV2(QueryExecutor.java:287)
at org.postgresql.core.QueryExecutor.execute(QueryExecutor.java:104)
at org.postgresql.core.QueryExecutor.execute(QueryExecutor.java:43)
org.postgresql.jdbc1.AbstractJdbc1Statement.execute(AbstractJdbc1Statement.
at java:517)
org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.
at java:50)
org.postgresql.jdbc1.AbstractJdbc1Statement.executeUpdate(AbstractJdbc1Stat
at ement.java:273)

if I e.g. try to perform an INSERT-statement.

The problem may also be present with other types than java.sql.Date, I
haven't checked the details.

The error is present in all versions 7.2-7.4 of the JDBC driver as far as I
can see.

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Bruno Wolff III 2004-06-22 13:57:20 Re: BUG #1176: PHP connection
Previous Message Richard Huxton 2004-06-22 12:10:25 Re: BUG #1176: PHP connection