SMALLINT vs short or... int?

From: Tomisław Kityński <hataraku(at)wp(dot)pl>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: SMALLINT vs short or... int?
Date: 2008-02-14 12:13:03
Message-ID: 47B4304F.5060204@wp.pl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Hello!

I found a problem with datatype conversion between SMALLINT and short. I
have noticed in archives that this problem should have been already
solved (there were some patches available), but this the problem is
still present in 8.2-504.jdbc3 jar I have been using. It didn't help to
upgrade to 8.3-603.jdbc4 (as I switched to Java 6.0, I did the same with
jdbc driver, that's why I use jdbc4 now and not jdbc3 as before). I
checked out the sources from repository yesterday (2008-02-14) and build
the driver with ant, but the problem persists.

The problem is above mentioned type conversion. According to
documentation psql's SMALLINT is int2 (just as short integer) and also
java.sql.Types have SMALLINT constant. I've noticed in the driver code,
there are places, where SMALLINT is converted to short (what is correct,
I believe). But when I call getObject on ResultSet instance on the the
column that is declared as SMALLINT i get an instance of Integer.

This is really a problem for me, as I use returned value's class for
reflection, namely obtaining a setter method with appropriate column
name AND type. I have method signature like this: setXXX(Short):void,
but java reflection can't find this, as getObject returns Integer, so
actually getDeclaredMethod uses Integer for the formal parameter (and
not Short, as it would be expected). I tracked the problem down, fixed,
and now the driver seems to work okay.

I created a patch, so please consider applying it. If this is not the
correct mailing list (I was not sure if the others are more
appropriate), then please point me to the correct one.

This is the patch (in switch clause there we SMALLINT and INTEGER case
sticked together, so conversion for SMALLINT worked the same way as for
INTEGER):

Best regards,
Tomislaw Kitynski

Index: AbstractJdbc2ResultSet.java
===================================================================
RCS file:
/cvsroot/jdbc/pgjdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java,v
retrieving revision 1.101
diff -r1.101 AbstractJdbc2ResultSet.java
122a123
> return new Short(getShort(columnIndex));

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Oliver Jowett 2008-02-14 12:22:05 Re: JDBC, prepared queries, and partitioning
Previous Message Simon Riggs 2008-02-14 12:07:56 Re: JDBC, prepared queries, and partitioning