Received: from localhost (unknown [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id D176A2E015A for ; Thu, 14 Feb 2008 08:13:16 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 62729-09 for ; Thu, 14 Feb 2008 08:13:07 -0400 (AST) Received: from mx1.wp.pl (mx1.wp.pl [212.77.101.5]) by postgresql.org (Postfix) with ESMTP id 5AFDB2E004B for ; Thu, 14 Feb 2008 08:13:13 -0400 (AST) Received: (wp-smtpd smtp.wp.pl 11673 invoked from network); 14 Feb 2008 13:13:03 +0100 Received: from proxy.pdk.com.pl (HELO [10.0.0.17]) (hataraku@[62.111.240.220]) (envelope-sender ) by smtp.wp.pl (WP-SMTPD) with AES256-SHA encrypted SMTP for ; 14 Feb 2008 13:13:03 +0100 Message-ID: <47B4304F.5060204@wp.pl> Date: Thu, 14 Feb 2008 13:13:03 +0100 From: =?ISO-8859-2?Q?Tomis=B3aw_Kity=F1ski?= User-Agent: Thunderbird 2.0.0.9 (Windows/20071031) MIME-Version: 1.0 To: pgsql-jdbc@postgresql.org Subject: SMALLINT vs short or... int? Content-Type: text/plain; charset=ISO-8859-2; format=flowed Content-Transfer-Encoding: 7bit X-WP-AV: skaner antywirusowy poczty Wirtualnej Polski S. A. X-WP-SPAM: NO 0000000 [wZN0] X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200802/89 X-Sequence-Number: 18296 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));