Re: Problems with BIT datatype and preparedStatment

From: Thomas Kellerer <spam_eater(at)gmx(dot)net>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: Problems with BIT datatype and preparedStatment
Date: 2012-11-26 13:12:49
Message-ID: k8vprl$vmg$1@ger.gmane.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Ermengol Bota, 26.11.2012 14:00:
> Hello,
>
> sql.execute("Create Table jdbc_demo (b bit)");
> PreparedStatement pstmt = conn.prepareStatement("insert into jdbc_demo values (?)");
> pstmt.setBoolean(1,true); // There is no way to set a value for the bit field (or I don't know ... :-)
> pstmt.execute();
>
> Theorically (I think) it should works, but it answers:
>
> ERROR: column "b" is of type bit but expression is of type boolean
>
> We are working with PG 9.2.1 (one-click-installer on Ubuntu) and JDBC4 9.2-1002
>
> After trying a lot of different types for the pstmt.setXXXX(), we think that there is something not working well, or we are missing something :-)
>

did you try

pstmt.setString(1, "1");

(I find the boolean type much more "descriptive" anyway for true/false columns)

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Ermengol Bota 2012-11-26 17:35:10 Re: Problems with BIT datatype and preparedStatment
Previous Message Ermengol Bota 2012-11-26 13:00:28 Problems with BIT datatype and preparedStatment