Re: Exception when inserting boolean values into BIT columns

From: Oliver Jowett <oliver(at)opencloud(dot)com>
To: Thomas Dudziak <tomdzk(at)gmail(dot)com>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: Exception when inserting boolean values into BIT columns
Date: 2005-06-20 12:10:32
Message-ID: 42B6B238.5090208@opencloud.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

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

In response to

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Thomas Dudziak 2005-06-20 12:23:37 Re: Exception when inserting boolean values into BIT columns
Previous Message David Gagnon 2005-06-20 11:35:57 Re: Problems with temporary tables created in callable functions