Thread: Integer is not a subclass of Short

Integer is not a subclass of Short

From
Lloyd Parkes
Date:
Hi all,
I have found a problem with a discrepancy between getColumnClassName()
in jdbc/pgjdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSetMetaData.java
and internalGetObject() in
jdbc/pgjdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java.

The former is defined (indirectly) to return the fully qualified class
name of (a possible superclass of) the object returned by the latter.
For a smallint column, the former returns "java.lang.Short", but the
latter returns a java.lang.Integer. Short is neither Integer, nor a
superclass of Integer.

I guess someone should add the line "return new
Short(getShort(columnIndex));" between lines 123 and 124 of rev 1.108 of
AbstractJdbc2ResultSet.java. There may be a similar problem with tinyint
columns, but I don't have any tinyint columns.

Cheers,
Lloyd


Re: Integer is not a subclass of Short

From
Kris Jurka
Date:

On Fri, 30 Jul 2010, Lloyd Parkes wrote:

> I have found a problem with a discrepancy between getColumnClassName()
> in jdbc/pgjdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSetMetaData.java
> and internalGetObject() in
> jdbc/pgjdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java.
>
> The former is defined (indirectly) to return the fully qualified class
> name of (a possible superclass of) the object returned by the latter.
> For a smallint column, the former returns "java.lang.Short", but the
> latter returns a java.lang.Integer. Short is neither Integer, nor a
> superclass of Integer.

According to my attached testcase getColumnClassName does return Integer.

> I guess someone should add the line "return new
> Short(getShort(columnIndex));" between lines 123 and 124 of rev 1.108 of
> AbstractJdbc2ResultSet.java. There may be a similar problem with tinyint
> columns, but I don't have any tinyint columns.

The spec requires the return type for smallint to be Integer.  See table
B-3 of the JDBC4 spec.

Kris Jurka

Re: Integer is not a subclass of Short

From
Kris Jurka
Date:

On Thu, 29 Jul 2010, Kris Jurka wrote:

> According to my attached testcase getColumnClassName does return Integer.
>

Actually attached now...

Kris Jurka

Attachment

Re: Integer is not a subclass of Short

From
Oliver Jowett
Date:
Lloyd Parkes wrote:
> Hi all,
> I have found a problem with a discrepancy between getColumnClassName()
> in jdbc/pgjdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSetMetaData.java
> and internalGetObject() in
> jdbc/pgjdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java.
>
> The former is defined (indirectly) to return the fully qualified class
> name of (a possible superclass of) the object returned by the latter.
> For a smallint column, the former returns "java.lang.Short", but the
> latter returns a java.lang.Integer. Short is neither Integer, nor a
> superclass of Integer.
>
> I guess someone should add the line "return new
> Short(getShort(columnIndex));" between lines 123 and 124 of rev 1.108 of
> AbstractJdbc2ResultSet.java. There may be a similar problem with tinyint
> columns, but I don't have any tinyint columns.

getObject() on a smallint column is correct to return an Integer (see
table B-3 in the JDBC spec), so if the metadata method is claiming it
should be a Short, then it's the metadata method that's wrong.

That said, I think you must be using a very old driver. The last time I
can see TypeInfoCache mapping int2 to "java.lang.Short" is back in the
8.1 driver branch. 8.2 and later should return "java.lang.Integer".

-O

Re: Integer is not a subclass of Short

From
Lloyd Parkes
Date:
Thanks Kris and Oliver. I have only referred to the Javadoc API and
not the JDBC spec because the API is online and Sun felt that the JDBC
spec is best published through their online shopping system behind
half a dozen "click here" pages.

So, let's start with the information I should have provided a while
back. I'm using Java 1.5.0 on a Mac with postgresql-8.4-701.jdbc3.jar.
I'm also using PostgreSQL server 8.3.

> That said, I think you must be using a very old driver. The last
> time I
> can see TypeInfoCache mapping int2 to "java.lang.Short" is back in the
> 8.1 driver branch. 8.2 and later should return "java.lang.Integer".

Hmm. That's interesting. I have some secret sauce in my program. I'm
using the Spring Framework to drive a whole bunch of stuff in my
program and one of the things I get it to do is to make the JDBC cruft
around the small amount of SQL I use go away. And then it turns out
that I am using two lots of secret sauce. The Spring Framework returns
a RowSet rather than a ResultSet. The RowSet is supposed to be an
extension of the ResultSet interface, but it is the RowSet that
doesn't work.

When I ran Kris' test case, it printed out "java.lang.Integer". When I
modified the program to use a com.sun.rowset.CachedRowSetImpl, it
printed out "java.lang.Short". I guess this is a bug in Oracle's JDBC
code.

Thanks for your help,
Lloyd


Attachment