pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Improper type conversion from smallint to short
6+ messages / 3 participants
[nested] [flat]

* Improper type conversion from smallint to short
@ 2013-03-14 22:27  Igor Urisman <igor.urisman@gmail.com>
  0 siblings, 2 replies; 6+ messages in thread

From: Igor Urisman @ 2013-03-14 22:27 UTC (permalink / raw)
  To: pgsql-jdbc

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

^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: Improper type conversion from smallint to short
@ 2013-03-15 00:27  Kris Jurka <books@ejurka.com>
  parent: Igor Urisman <igor.urisman@gmail.com>
  1 sibling, 1 reply; 6+ messages in thread

From: Kris Jurka @ 2013-03-15 00:27 UTC (permalink / raw)
  To: Igor Urisman <igor.urisman@gmail.com>; +Cc: pgsql-jdbc



On Thu, 14 Mar 2013, Igor Urisman wrote:

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

Returning Integer is correct according to the JDBC spec.  See table 8.6.3 
here:

http://www.cis.upenn.edu/~bcpierce/courses/629/jdkdocs/guide/jdbc/getstart/mapping.doc.html

Kris Jurka
-- 
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc



^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: Improper type conversion from smallint to short
@ 2013-03-15 01:17  Igor Urisman <igor.urisman@gmail.com>
  parent: Kris Jurka <books@ejurka.com>
  0 siblings, 1 reply; 6+ messages in thread

From: Igor Urisman @ 2013-03-15 01:17 UTC (permalink / raw)
  To: Kris Jurka <books@ejurka.com>; +Cc: pgsql-jdbc

Thanks, Kris.  Not to argue... The spec you're quoting from is pre Java
1.1, which is when Short was introduced.  (Integer was in 1.0).  Just
thinking...  That same spec recommends primitive short.  Just sayin'.
-Igor.


On Thu, Mar 14, 2013 at 5:27 PM, Kris Jurka <books@ejurka.com> wrote:

>
>
> On Thu, 14 Mar 2013, Igor Urisman wrote:
>
> > Hello,It appears that ResultSet.getObject(String name) returns Integer
> for
> > database type Types.SMALLINT (5)  I expected Short.
> >
>
> Returning Integer is correct according to the JDBC spec.  See table 8.6.3
> here:
>
>
> http://www.cis.upenn.edu/~bcpierce/courses/629/jdkdocs/guide/jdbc/getstart/mapping.doc.html
>
> Kris Jurka

^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: Improper type conversion from smallint to short
@ 2013-03-15 02:29  Kris Jurka <books@ejurka.com>
  parent: Igor Urisman <igor.urisman@gmail.com>
  0 siblings, 0 replies; 6+ messages in thread

From: Kris Jurka @ 2013-03-15 02:29 UTC (permalink / raw)
  To: Igor Urisman <igor.urisman@gmail.com>; +Cc: pgsql-jdbc



On Thu, 14 Mar 2013, Igor Urisman wrote:

> Thanks, Kris.  Not to argue... The spec you're quoting from is pre Java 1.1,
> which is when Short was introduced.  (Integer was in 1.0).  Just thinking...
>  That same spec recommends primitive short.  Just sayin'. -Igor.

That was just the first link I happened to find.  The specs are in PDF 
format that makes linking tough, but if you check the current spec you'll 
see the same table, but with this note:

Note . The JDBC 1.0 specification defined the Java object mapping for the
SMALLINT and TINYINT JDBC types to be Integer. The Java language did not
include the Byte and Short data types when the JDBC 1.0 specification was
finalized. The mapping of SMALLINT and TINYINT to Integer is maintained to
preserve backwards compatibility.

Kris Jurka
-- 
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc



^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: Improper type conversion from smallint to short
@ 2013-03-15 12:56  Kevin Grittner <kgrittn@ymail.com>
  parent: Igor Urisman <igor.urisman@gmail.com>
  1 sibling, 1 reply; 6+ messages in thread

From: Kevin Grittner @ 2013-03-15 12:56 UTC (permalink / raw)
  To: Igor Urisman <igor.urisman@gmail.com>; pgsql-jdbc

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


-- 
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc



^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* Re: Improper type conversion from smallint to short
@ 2013-03-18 04:02  Igor Urisman <igor.urisman@gmail.com>
  parent: Kevin Grittner <kgrittn@ymail.com>
  0 siblings, 0 replies; 6+ messages in thread

From: Igor Urisman @ 2013-03-18 04:02 UTC (permalink / raw)
  To: Kevin Grittner <kgrittn@ymail.com>; +Cc: 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
>

^ permalink  raw  reply  [nested|flat] 6+ messages in thread


end of thread, other threads:[~2013-03-18 04:02 UTC | newest]

Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2013-03-14 22:27 Improper type conversion from smallint to short Igor Urisman <igor.urisman@gmail.com>
2013-03-15 00:27 ` Kris Jurka <books@ejurka.com>
2013-03-15 01:17   ` Igor Urisman <igor.urisman@gmail.com>
2013-03-15 02:29     ` Kris Jurka <books@ejurka.com>
2013-03-15 12:56 ` Kevin Grittner <kgrittn@ymail.com>
2013-03-18 04:02   ` Igor Urisman <igor.urisman@gmail.com>

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