Skip site navigation (1) Skip section navigation (2)

Re: [PATCHES] Anoter JDBC Error

From: Kris Jurka <books(at)ejurka(dot)com>
To: Aaron Mulder <ammulder(at)alumni(dot)princeton(dot)edu>
Cc: PostgreSQL JDBC <pgsql-jdbc(at)postgresql(dot)org>,<pgsql-patches(at)postgresql(dot)org>
Subject: Re: [PATCHES] Anoter JDBC Error
Date: 2002-10-22 21:14:00
Message-ID: Pine.LNX.4.33.0210221513400.424-200000@leary.csoft.net (view raw or flat)
Thread:
Lists: pgsql-jdbcpgsql-patches
The following patch fixes this bug and the potential source of similar
bugs.  When creating the ResultSets for DatabaseMetaData calls, the code
creates byte arrays for each row something like...

byte tuple[][] = new byte[18][0];

Unless a call "tuple[n] = null;" is made then it has an array of zero
length which does in fact get turned into the zero length string being
seen.  I have changed these allocations to...

byte tuple[][] = new byte[18][];

Kris Jurka


On Sat, 19 Oct 2002, Aaron Mulder wrote:

> 	Ahh, never mind.  I tried again a few minutes later, and got the
> new behavior, which is to say a SQLException.  But I don't
> understand why this is happening.  Here's what I'm doing:
>
> 	I create the database "test" (in my PG 7.2.2 DB) with a table with
> 3 columns, all integers.  I connect using the JDBC3 driver, get a
> connection, get the databasemetadata, call
>
> 	dbmd.getColumns("test",null,"tablename","%");
>
> 	I get back a ResultSet.  Column 9 is an integer column,
> DECIMAL_DIGITS.  If I call getObject, it tries to get an Integer object,
> so even the ResultSet thinks it's an integer column.  However, the result
> of getString/getFixedString used for new Integer(getFixedString()) is
> apparently an empty String, causing the SQLException due to a badly
> formatted Integer value.
>
> 	So now I'm confused.  What's an empty String doing in an integer
> column when (if you believe the logic in getFixedString) the value was not
> null?  Is this broken null handling?  Test program and results attached...
>
> Aaron
>
> import java.sql.*;
>
> public class PostgresTest{
>     public static void main(String args[]) {
>         try {
>             Class.forName("org.postgresql.Driver");
>             Connection con =
> DriverManager.getConnection("jdbc:postgresql://localhost/test", "test",
> "password");
>             DatabaseMetaData dmd = con.getMetaData();
>             ResultSet rs = dmd.getColumns("test", null, "tablename", "%");
>             rs.next();
>             System.out.println("Col 9: "+rs.getInt(9)); // getObject(9)
>             rs.close();
>             con.close();
>         } catch(Exception e) {
>             e.printStackTrace();
>         }
>     }
> }
>
>
> Bad Integer
> 	at
> org.postgresql.jdbc1.AbstractJdbc1ResultSet.toInt(AbstractJdbc1ResultSet.java:708)
> 	at
> org.postgresql.jdbc1.AbstractJdbc1ResultSet.getInt(AbstractJdbc1ResultSet.java:148)
> 	at PostgresTest.main(PostgresTest.java:12)
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://archives.postgresql.org
>


Attachment: decimaldigits.patch
Description: text/plain (5.7 KB)

In response to

Responses

pgsql-patches by date

Next:From: Bruce MomjianDate: 2002-10-23 19:22:54
Subject: Re: [BUGS] psql does not invoke pager on \h *
Previous:From: Peter EisentrautDate: 2002-10-22 17:42:08
Subject: Re: swedish translation

pgsql-jdbc by date

Next:From: Kris JurkaDate: 2002-10-22 21:41:02
Subject: Re: build.xml patch
Previous:From: Michael PaesoldDate: 2002-10-22 20:32:58
Subject: Re: new String(byte[]) performance

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group