Re: Possible to say: [setObject("123")] to insert into int

From: Oliver Jowett <oliver(at)opencloud(dot)com>
To: "j(dot)random(dot)programmer" <javadesigner(at)yahoo(dot)com>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: Possible to say: [setObject("123")] to insert into int
Date: 2006-06-29 00:55:37
Message-ID: 44A32509.8080108@opencloud.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

j.random.programmer wrote:

> This will throw a Driver exception. Is this expected
> behavior
> or should the driver do a Integer.parseInt(...) on the
> string value
> as needed ?
>
> This is not a show-stopper or even a serious bug in my
> code
> and is easy to workaround. I'm just curious as to the
> "right"
> behavior as per the JDBC spec.....

I've found nothing in the JDBC spec to say that the driver is required
to do an implicit conversion of String to integer (if you found
something that says it is required, can you let me know where?).

If you explicitly specify a target SQL type (i.e.
'setObject(1,"123",Types.INTEGER)'), the driver will do the conversion
for you. But if you don't specify a type, the driver infers the SQL type
from the Java type of the object, per the rules in the JDBC spec -- in
this case, VARCHAR for a String object.

Or you could pass 'stringtype=unspecified' as a JDBC URL parameter which
means that String parameters aren't typed at all when passed to the
server (and the server tries to infer the type from the query).

-O

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Tamás Barta 2006-06-29 07:34:59 Re: JDBC Driver
Previous Message j.random.programmer 2006-06-28 22:46:05 Possible to say: [setObject("123")] to insert into int column type ?