Re: Improper type conversion from smallint to short - Mailing list pgsql-jdbc

From Igor Urisman
Subject Re: Improper type conversion from smallint to short
Date
Msg-id CAJ9OwnU6W+Wc9=mBXSOe3amkDRvoWArdpFCqp_6pW8cPMs6mLw@mail.gmail.com
Whole thread Raw
In response to Re: Improper type conversion from smallint to short  (Kevin Grittner <kgrittn@ymail.com>)
List pgsql-jdbc
Thanks, Kevin & Kris. 

I should have looked this up myself.  Just seemed hard to fathom that the following code shouldn't work:

import java.lang.reflect.Field;
...
Field f = reflectFieldOfInterest();
f.set(this, resultSet.getObject("some_column"));

The last statement bombs on Integer to short assignment even though, by my reckoning, ResultSet.getObject() exists precisely for this use case.

-Igor.


-Igor.


On Fri, Mar 15, 2013 at 5:56 AM, Kevin Grittner <kgrittn@ymail.com> wrote:
Igor Urisman <igor.urisman@gmail.com> wrote:

> It appears that ResultSet.getObject(String name) returns Integer
> for database type Types.SMALLINT (5)  I expected Short.

I count on drivers complying with the published specification.  The
most recent version I was able to find near the top of a quick web
search was this (the Final Release of the JDBC 4.0 Specification):

http://download.oracle.com/otn-pub/jcp/jdbc-4.0-fr-eval-oth-JSpec/jdbc-4_0-fr-spec.zip

Take a look at the "Data Type Conversion Tables" in appendix B.  In
particular, table B-3 specifies which Java object class should be
returned by the getObject methods for each JDBC type.  To do as you
request would break the applications of everyone who trusts the
specification published through the Java Community Process.

--
Kevin Grittner
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

pgsql-jdbc by date:

Previous
From: Bryan Varner
Date:
Subject: Re: Re: [pgjdbc] XADataSource support for resource sharing & interleaving. (#47)
Next
From: Kevin Grittner
Date:
Subject: Re: Re: [pgjdbc] XADataSource support for resource sharing & interleaving. (#47)