dbTalk Databases Forums  

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

mailing.database.pgsql-bugs mailing.database.pgsql-bugs


Discuss [BUGS] BUG #1177: JDBC driver doesn't handle all dates correctly in the mailing.database.pgsql-bugs forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
PostgreSQL Bugs List
 
Posts: n/a

Default [BUGS] BUG #1177: JDBC driver doesn't handle all dates correctly - 06-22-2004 , 07:25 AM







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(QueryE xecutor.java:287)
at org.postgresql.core.QueryExecutor.execute(QueryExe cutor.java:104)
at org.postgresql.core.QueryExecutor.execute(QueryExe cutor.java:43)
org.postgresql.jdbc1.AbstractJdbc1Statement.execut e(AbstractJdbc1Statement.
at java:517)
org.postgresql.jdbc2.AbstractJdbc2Statement.execut e(AbstractJdbc2Statement.
at java:50)
org.postgresql.jdbc1.AbstractJdbc1Statement.execut eUpdate(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.


---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Reply With Quote
  #2  
Old   
Kris Jurka
 
Posts: n/a

Default Re: [BUGS] BUG #1177: JDBC driver doesn't handle all dates correctly - 06-22-2004 , 05:41 PM








On Tue, 22 Jun 2004, PostgreSQL Bugs List wrote:

Quote:
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
Description: JDBC driver doesn't handle all dates correctly

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));

I was originally going to label this as a Java bug, but according to this
discussion (login required):

http://bugs.sun.com/bugdatabase/view...bug_id=4510956

they have no intention of making toString work for year values > 9999.
I'll look at working around this on the driver side.

Kris Jurka

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo (AT) postgresql (DOT) org so that your
message can get through to the mailing list cleanly


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.