Re: smallint mapping issue - Mailing list pgsql-jdbc

From Oliver Jowett
Subject Re: smallint mapping issue
Date
Msg-id 42E80EF4.6000505@opencloud.com
Whole thread Raw
In response to smallint mapping issue  (Christian Cryder <c.s.cryder@gmail.com>)
Responses Re: smallint mapping issue  (Christian Cryder <c.s.cryder@gmail.com>)
List pgsql-jdbc
Christian Cryder wrote:

> Dave tells me this has been discussed recently, but doesn't recall the
> thread, so I'll post here.

You might want to search on archives.postgresql.org too.

> In postgresql-8.0-311.jdbc3.jar with a column defined as smallint, the
> corresponding value returned from getObject() is a Short.
>
> In the current HEAD, that same smallint column is returned as an Integer.

Please see table B-3 in the JDBC 3.0 spec:

TABLE B-3 JDBC Types Mapped to Java Object Types
ResultSet.getObject and CallableStatement.getObject use the mapping
shown in this table for standard mappings

[...]

TINYINT Integer
SMALLINT Integer
INTEGER Integer
BIGINT Long

> This causes HUGE problems if it's not an oversight, as it makes it
> virtually impossible to write JDBC code that works with other dbs
> (which typically return Short).

Which other DBs exactly? You should tell them to fix their JDBC drivers :)

It's easy enough to deal with both Short and Integer being returned --
cast to java.lang.Number.

> Can someone confirm that this is a bug, and if not, a) why (given the
> above documentation), and b) how do you expect to deal with the
> incompatibility issues this would cause?

It's not a bug -- it's a deliberate change so that we actually follow
the spec.

Personally I'm not prepared to put much effort into supporting backwards
compatibility with old behaviour that was not spec compliant. Fix your
application.

-O

pgsql-jdbc by date:

Previous
From: Oliver Jowett
Date:
Subject: Re: jdbc xa patches
Next
From: "Byron Nikolaidis"
Date:
Subject: Date problem on Aix jdk1.4.1