X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id B491752813 for ; Mon, 20 Jun 2005 09:10:42 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 21195-02 for ; Mon, 20 Jun 2005 12:10:33 +0000 (GMT) Received: from yass.opencloud.co.nz (yass.opencloud.co.nz [203.79.85.162]) by svr1.postgresql.org (Postfix) with ESMTP id 9A3255283D for ; Mon, 20 Jun 2005 09:10:31 -0300 (ADT) Received: from 203-79-104-60.cable.paradise.net.nz ([203.79.104.60] helo=[192.168.0.20]) by yass.opencloud.co.nz with asmtp (TLS-1.0:DHE_RSA_AES_128_CBC_SHA:16) (Exim 4.34) id 1DkL6n-0005V3-Uf; Tue, 21 Jun 2005 00:10:34 +1200 Message-ID: <42B6B238.5090208@opencloud.com> Date: Tue, 21 Jun 2005 00:10:32 +1200 From: Oliver Jowett User-Agent: Mozilla Thunderbird 1.0.2 (X11/20050324) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Thomas Dudziak Cc: pgsql-jdbc@postgresql.org Subject: Re: Exception when inserting boolean values into BIT columns References: <224f3234050620030565ffa711@mail.gmail.com> In-Reply-To: <224f3234050620030565ffa711@mail.gmail.com> X-Enigmail-Version: 0.90.2.0 X-Enigmail-Supports: pgp-inline, pgp-mime Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.004 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200506/103 X-Sequence-Number: 13065 Thomas Dudziak wrote: > I have a problem with BIT datatypes accessed via JDBC. When I try to > insert a Boolean value via a PreparedStatement, I get the following > exception (using the newest JDBC driver, postgresql-8.0-311.jdbc3.jar, > against a 8.0.1 database on Windows, Java is 1.5.0_1): > > Exception in thread "main" java.sql.SQLException: ERROR: column "isok" > is of type bit but expression is of type boolean As I understand it, JDBC's BIT/BOOLEAN types (single boolean value) aren't the same as PostgreSQL's BIT type (bit string). The JDBC driver maps setBoolean(), setObject(...,Types.BIT), and setObject(...,Types.BOOLEAN) to the 'boolean' datatype. Try using the boolean type in your schema, assuming what you want to store is a single boolean value. If you really want a bitstring, you'll probably need to do something nasty like pass the value via setString() and use 'pg_catalog.bit(?)' in your query to do the type conversion (CAST AS doesn't seem to work from brief testing) -O