Re: Bug: Driver(8.2dev-500.jdbc3) does not handle boolean->BIT - Mailing list pgsql-jdbc

From Oliver Jowett
Subject Re: Bug: Driver(8.2dev-500.jdbc3) does not handle boolean->BIT
Date
Msg-id 43A742F0.8040801@opencloud.com
Whole thread Raw
In response to Bug: Driver(8.2dev-500.jdbc3) does not handle boolean->BIT correctly  ("j.random.programmer" <javadesigner@yahoo.com>)
Responses Re: Bug: Driver(8.2dev-500.jdbc3) does not handle boolean->BIT correctly  ("j.random.programmer" <javadesigner@yahoo.com>)
List pgsql-jdbc
j.random.programmer wrote:
> Running against postgres 8.1
>
> I have:
>
> create table foo (bit_val bit);
>
> If I now try to insert, via the driver's prepared
> statement, a value of java boolean true into
> the bit_val column, I get:
>
> ---------------------------------
> ERROR COULD NOT SAVE.....
> org.postgresql.util.PSQLException: ERROR: column
> "bit_val" is of type bit but expression is of type
> boolean
> ---------------------------------

JDBC's "BIT" is actually a boolean type. In JDBC3, BIT and BOOLEAN are
effectively equivalent.

The backend's "bit" type is actually a bitstring that does not have a
direct equivalent in JDBC.

> This is totally wrong if my reading of the JDBC
> spec is correct. Java boolean values should
> be converted to bitval(1), possibly as '1' and
> then converted back to boolean when read from
> the database.

Actually, the spec says nothing about bitstring types AFAIK.

If you want to do this type conversion and still use setBoolean(), you
will need to modify your query to do the type conversion there.

-O

pgsql-jdbc by date:

Previous
From: Oliver Jowett
Date:
Subject: Re: 8.2dev-500.jdbc3 driver: PreparedStatement.toString()
Next
From: "j.random.programmer"
Date:
Subject: Re: 8.2dev-500.jdbc3 driver: PreparedStatement.toString() is buggy