From: Oliver Jowett <oliver@opencloud.com>
To: Thomas Dudziak <tomdzk@gmail.com>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: Exception when inserting boolean values into BIT columns
Date: Tue, 21 Jun 2005 00:10:32 +1200
Message-ID: <42B6B238.5090208@opencloud.com> (raw)
In-Reply-To: <224f3234050620030565ffa711@mail.gmail.com>
References: <224f3234050620030565ffa711@mail.gmail.com>
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
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: oliver@opencloud.com, tomdzk@gmail.com
Subject: Re: Exception when inserting boolean values into BIT columns
In-Reply-To: <42B6B238.5090208@opencloud.com>
References: <224f3234050620030565ffa711@mail.gmail.com> <42B6B238.5090208@opencloud.com>
* 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