pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Kris Jurka <books@ejurka.com>
To: Dave Cramer <pg@fastcrypt.com>
Cc: Srinivas Gunnam <srinivas_gunnam@persistent.co.in>
Cc: pgsql-jdbc@postgresql.org <pgsql-jdbc@postgresql.org>
Subject: Re: Throwing NumberFormat exception for preparedStatement.setObjcet()
Date: Wed, 13 Jan 2010 17:36:52 -0500 (EST)
Message-ID: <alpine.BSO.2.00.1001131733040.3231@leary.csoft.net> (raw)
In-Reply-To: <491f66a51001120345o78aa2597n3c9f7f281a57baed@mail.gmail.com>
References: <14B8F27D7CE40C4C9E481B2B845C2E0D724677A2@EXCHANGE.persistent.co.in>
	<491f66a51001111215l5ef09181j288d4d583bf007e4@mail.gmail.com>
	<14B8F27D7CE40C4C9E481B2B845C2E0D72467E0F@EXCHANGE.persistent.co.in>
	<491f66a51001120345o78aa2597n3c9f7f281a57baed@mail.gmail.com>



On Tue, 12 Jan 2010, Dave Cramer wrote:

> If I were writing it I would use java.sql.Types.Integer as the
> columnType, not the numeric value. And inputData should be an Integer.
>

inputData can perfectly well be a String.  That's the whole point of the 
three argument version of this method, to provide such a conversion for 
the user.

The reason it's throwing a NumberFormatException is that you're passing 
something which isn't a number.  With a later driver version you wouldn't 
get this exception, but instead the server would complain that it wasn't a 
valid number.

The attached test case shows this working just fine from my perspective.

Kris Jurka

Attachments:

SetObjectTest.java (text/plain, 604B) download import java.sql.*; public class SetObjectTest { public static void main(String args[]) throws Exception { Class.forName("org.postgresql.Driver"); Connection conn = DriverManager.getConnection("jdbc:postgresql://[::1]:5432/jurka", "jurka", ""); Statement stmt = conn.createStatement(); stmt.execute("CREATE TEMP TABLE sot(a int)"); stmt.close(); PreparedStatement ps = conn.prepareStatement("INSERT INTO sot VALUES (?)"); ps.setObject(1, "1", 3); ps.executeUpdate(); ps.setObject(1, "A", 3); ps.executeUpdate(); ps.close(); conn.close(); } }

view thread (7+ messages)  latest in thread

Message-ID: <alpine.BSO.2.00.1001131733040.3231@leary.csoft.net>
Permalink:  ../alpine.BSO.2.00.1001131733040.3231@leary.csoft.net/
Also on:    postgresql.org/message-id/alpine.BSO.2.00.1001131733040.3231@leary.csoft.net

 · 

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: books@ejurka.com, pg@fastcrypt.com, srinivas_gunnam@persistent.co.in
  Subject: Re: Throwing NumberFormat exception for preparedStatement.setObjcet()
  In-Reply-To: <alpine.BSO.2.00.1001131733040.3231@leary.csoft.net>
  References: <14B8F27D7CE40C4C9E481B2B845C2E0D724677A2@EXCHANGE.persistent.co.in> <491f66a51001111215l5ef09181j288d4d583bf007e4@mail.gmail.com> <14B8F27D7CE40C4C9E481B2B845C2E0D72467E0F@EXCHANGE.persistent.co.in> <491f66a51001120345o78aa2597n3c9f7f281a57baed@mail.gmail.com> <alpine.BSO.2.00.1001131733040.3231@leary.csoft.net>

* 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