From: Kris Jurka <books@ejurka.com>
To: David Pinheiro <davidsantospinheiro@gmail.com>
Cc: pgsql-bugs@postgresql.org
Cc: pgsql-jdbc@postgresql.org
Subject: Re: BUG #6292: java.sql.PreparedStatement.setNull() throws PSQLException
Date: Wed, 16 Nov 2011 16:38:46 -0500 (EST)
Message-ID: <alpine.BSO.2.00.1111161635310.14447@leary.csoft.net> (raw)
In-Reply-To: <201111141631.pAEGV2pt071873@wwwmaster.postgresql.org>
References: <201111141631.pAEGV2pt071873@wwwmaster.postgresql.org>
On Mon, 14 Nov 2011, David Pinheiro wrote:
>
> Bug reference: 6292
> PostgreSQL version: 8.4
> Description: java.sql.PreparedStatement.setNull() throws
> PSQLException
> Details:
>
> I'm trying to make:
> java.sql.PreparedStatement.setNull(1,java.sql.Types.NULL);
>
> org.postgresql.util.PSQLException: ERROR: column "number_column" is of type
> integer but expression is of type character varying
> Hint: You will need to rewrite or cast the expression.
>
>
> My code is something like:
> if (String.valueOf(input_field) == "null"){
> statement.setNull(1, java.sql.Types.NULL);
> } else {
> statement.setObject(1, valor);
> }
> statement.executeUpdate();
>
I don't think your problem is with setNull, I think your problem is
actually with the setObject branch of your if statement. If the
valor variable is a String, the JDBC driver is assigning it a string
type. You may want to do setObject(1, valor, Types.INTEGER) or
convert it prior to doing the setObject call to an appropriate
numeric type.
Kris Jurka
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, davidsantospinheiro@gmail.com, pgsql-bugs@postgresql.org
Subject: Re: BUG #6292: java.sql.PreparedStatement.setNull() throws PSQLException
In-Reply-To: <alpine.BSO.2.00.1111161635310.14447@leary.csoft.net>
References: <201111141631.pAEGV2pt071873@wwwmaster.postgresql.org> <alpine.BSO.2.00.1111161635310.14447@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