Re: smallint mapping issue

From: Oliver Jowett <oliver(at)opencloud(dot)com>
To: Christian Cryder <c(dot)s(dot)cryder(at)gmail(dot)com>
Cc: "pgsql-jdbc(at)postgresql(dot)org" <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: smallint mapping issue
Date: 2005-07-27 22:47:16
Message-ID: 42E80EF4.6000505@opencloud.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Byron Nikolaidis 2005-07-27 22:51:17 Date problem on Aix jdk1.4.1
Previous Message Oliver Jowett 2005-07-27 22:37:47 Re: jdbc xa patches