Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 1E50BA49A11 for ; Wed, 16 Nov 2011 17:39:07 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 86409-06; Wed, 16 Nov 2011 21:39:00 +0000 (UTC) Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id B24C8A49A0F; Wed, 16 Nov 2011 17:39:00 -0400 (AST) Received: from mail63.csoft.net ([205.205.214.4]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1RQnC7-0000sS-W0; Wed, 16 Nov 2011 21:39:00 +0000 Received: from mail63.csoft.net (localhost [127.0.0.1]) by mail63.csoft.net (Postfix) with ESMTP id 4A74D284DB; Wed, 16 Nov 2011 16:38:47 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=csoft.net; h=date:from:to :cc:subject:in-reply-to:message-id:references:mime-version :content-type; s=sel1; bh=/7FZfkR5dKmgLFerT4N1xc6KqBQ=; b=V45qA+ jPV2EoWYcg3MI5BBnPda+nDqbiyg/eOJK05FKWpQG2EakNBSZM3TXPQ7WPuwXhx4 SU3qXspmCHZhaer1Kh1e4ZFoAC19dWptguMw5kw7b3zRogHPMFTdTNkOE/FbIDKh y/wY51RF+2LdxeHxwX+3a3uwEDs0DcyThevSc= Received: from leary.csoft.net (leary.csoft.net [205.205.214.5]) by mail63.csoft.net (Postfix) with ESMTP id 4244328430; Wed, 16 Nov 2011 16:38:47 -0500 (EST) Received: by leary.csoft.net (Postfix, from userid 1112) id 0F442A188; Wed, 16 Nov 2011 16:38:46 -0500 (EST) Date: Wed, 16 Nov 2011 16:38:46 -0500 (EST) From: Kris Jurka X-X-Sender: books@leary.csoft.net To: David Pinheiro cc: pgsql-bugs@postgresql.org, pgsql-jdbc@postgresql.org Subject: Re: BUG #6292: java.sql.PreparedStatement.setNull() throws PSQLException In-Reply-To: <201111141631.pAEGV2pt071873@wwwmaster.postgresql.org> Message-ID: References: <201111141631.pAEGV2pt071873@wwwmaster.postgresql.org> User-Agent: Alpine 2.00 (BSO 1167 2008-08-23) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-5 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201111/119 X-Sequence-Number: 31714 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