Re: Improper type conversion from smallint to short

Поиск
Список
Период
Сортировка
От Igor Urisman
Тема Re: Improper type conversion from smallint to short
Дата
Msg-id CAJ9OwnU6W+Wc9=mBXSOe3amkDRvoWArdpFCqp_6pW8cPMs6mLw@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Improper type conversion from smallint to short  (Kevin Grittner <kgrittn@ymail.com>)
Список 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 по дате отправления:

Предыдущее
От: Bryan Varner
Дата:
Сообщение: Re: Re: [pgjdbc] XADataSource support for resource sharing & interleaving. (#47)
Следующее
От: Kevin Grittner
Дата:
Сообщение: Re: Re: [pgjdbc] XADataSource support for resource sharing & interleaving. (#47)