pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Oliver Jowett <oliver@opencloud.com>
To: j.random.programmer <javadesigner@yahoo.com>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: Possible to say: [setObject("123")] to insert into int
Date: Thu, 29 Jun 2006 09:55:37 +0900
Message-ID: <44A32509.8080108@opencloud.com> (raw)
In-Reply-To: <20060628224605.94631.qmail@web32014.mail.mud.yahoo.com>
References: <20060628224605.94631.qmail@web32014.mail.mud.yahoo.com>

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



view thread (2+ messages)

Message-ID: <44A32509.8080108@opencloud.com>
Permalink:  ../44A32509.8080108@opencloud.com/
Also on:    postgresql.org/message-id/44A32509.8080108@opencloud.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: oliver@opencloud.com, javadesigner@yahoo.com
  Subject: Re: Possible to say: [setObject("123")] to insert into int
  In-Reply-To: <44A32509.8080108@opencloud.com>
  References: <20060628224605.94631.qmail@web32014.mail.mud.yahoo.com> <44A32509.8080108@opencloud.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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