X-Original-To: pgsql-jdbc-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 671CB9FA60B for ; Wed, 28 Jun 2006 21:55:57 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 61733-10 for ; Wed, 28 Jun 2006 21:55:51 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from yass.opencloud.co.nz (yass.opencloud.co.nz [131.203.101.226]) by postgresql.org (Postfix) with ESMTP id AD2589FA319 for ; Wed, 28 Jun 2006 21:55:50 -0300 (ADT) Received: from 221x253x225x162.ap221.ftth.ucom.ne.jp ([221.253.225.162] helo=[192.168.1.169]) by yass.opencloud.co.nz with asmtp (TLS-1.0:DHE_RSA_AES_128_CBC_SHA:16) (Exim 4.34) id 1Fvkos-0004Va-B3; Thu, 29 Jun 2006 12:55:46 +1200 Message-ID: <44A32509.8080108@opencloud.com> Date: Thu, 29 Jun 2006 09:55:37 +0900 From: Oliver Jowett User-Agent: Mozilla Thunderbird 1.0.8 (X11/20060502) X-Accept-Language: en-us, en MIME-Version: 1.0 To: "j.random.programmer" CC: pgsql-jdbc@postgresql.org Subject: Re: Possible to say: [setObject("123")] to insert into int References: <20060628224605.94631.qmail@web32014.mail.mud.yahoo.com> In-Reply-To: <20060628224605.94631.qmail@web32014.mail.mud.yahoo.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200606/134 X-Sequence-Number: 15414 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