pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tomisław Kityński <hataraku@wp.pl>
To: pgsql-jdbc@postgresql.org
Subject: SMALLINT vs short or... int?
Date: Thu, 14 Feb 2008 13:13:03 +0100
Message-ID: <47B4304F.5060204@wp.pl> (raw)

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));




view thread (2+ messages)  latest in thread

Message-ID: <47B4304F.5060204@wp.pl>
Permalink:  ../47B4304F.5060204@wp.pl/
Also on:    postgresql.org/message-id/47B4304F.5060204@wp.pl

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: hataraku@wp.pl
  Subject: Re: SMALLINT vs short or... int?
  In-Reply-To: <47B4304F.5060204@wp.pl>
  References: <47B4304F.5060204@wp.pl>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox