From: | Barry Lind <barry(at)xythos(dot)com> |
---|---|
To: | Kevin Schmidt <kevin(dot)schmidt(at)enterworks(dot)com> |
Cc: | pgsql-jdbc(at)postgresql(dot)org |
Subject: | Re: setBoolean with BIT column |
Date: | 2002-09-18 17:06:35 |
Message-ID: | 3D88B29B.7080406@xythos.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-jdbc |
Kevin,
BOOLEAN is the correct data type for the table. BIT is not. The BIT
datatype is a variable length datatype. So you can create a table like
the following:
create table testbit (a bit(10));
So the column a is of datatype bit, but of length 10 (i.e. 10 bits).
Clearly setBoolean() isn't the correct method to be using to set the BIT
value in this case.
In postgres SQL_TYPES.BIT = the BOOLEAN datatype. Where the BIT
datatype has different symantics than SQL_TYPES.BIT.
thanks,
--Barry
Kevin Schmidt wrote:
> Hi,
>
> I am using PostgreSQL 7.2 and have a column of type BIT that I am
> inserting into with a PreparedStatement. In reading the Javadoc for
> PreparedStatement, the setBoolean() method seems to be the correct way
> to set a parameter for a BIT datatype as the description for the method is:
>
> "Sets the designated parameter to the given Java boolean value. The
> driver converts this to an SQL BIT value when it sends it to the database."
>
> When I try this though, I get an error:
>
> "cannot parse t as a binary digit"
>
> In looking at the PreparedStatement's SQL, it seems to be constructing
> something like:
>
> insert into myTable values('t')
>
> which would explain the error message.
>
> So, is this a bug in the JDBC driver in that it doesn't do the
> conversion to an SQL BIT value when sent to the database like the
> Javadoc says? If not, what is the correct way to set a parameter to a
> BIT value in a PreparedStatement?
>
> I know I can probably use a BOOLEAN column and things will work fine,
> but I expected this to work using a BIT datatype.
>
> Thanks,
>
> Kevin
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
>
From | Date | Subject | |
---|---|---|---|
Next Message | Barry Lind | 2002-09-18 17:08:14 | Re: [GENERAL] Postgres 7.3b1 + JDBC3 (2002-09-05) truncates SQL |
Previous Message | Barry Lind | 2002-09-18 16:30:08 | Re: NOTICE causing SQLException |