Re: Problems with BIT datatype and preparedStatment - Mailing list pgsql-jdbc

From Ermengol Bota
Subject Re: Problems with BIT datatype and preparedStatment
Date
Msg-id CABX=gB5B2wyW0oAmugaB2gMQz3LdmASjACjxhGfA38HMgCEq9A@mail.gmail.com
Whole thread Raw
In response to Problems with BIT datatype and preparedStatment  (Ermengol Bota <ebota@uoc.edu>)
Responses Re: Problems with BIT datatype and preparedStatment
List pgsql-jdbc
2012/11/26 dmp <danap@ttc-cmc.net>
Hello,

A search of the forum may turn up a better answer, but:

I searched "the web" :-D and I just found the code below that it's supposed to work. I thought that the patch sended was included "by default" in newer jdbc versions...


btw, which forum do you refer?


So the first problem with your execution above is you have tried to
insert a PostgreSQL boolean type into a defined PostgreSQL bit type.
You definition is actually by default bit(1), it could have been
bit(2) has the example bit2_type above. Can not use setBoolean() with
bit type in the way you have tried.

The one way that it can be done has I have seen before would be to
do a CAST.

pstmt = con.prepareStatement("INSERT INTO jdbc_demo VALUES (?::bit)");
pstmt.setString(1, "1");

This way works! great :-)

I'm not used to do cast conversion on the prepareStatement definition, thank you for the clue!

Now I see that I didn't understand the hint at the error message "Hint: You will need to rewrite or cast the expression."

Thanks a lot.

--
* Ermengol *
*************************************************
* Els ordinadors no resolen problemes, *
* simplement executen solucions           *
*************************************************

pgsql-jdbc by date:

Previous
From: dmp
Date:
Subject: Re: Problems with BIT datatype and preparedStatment
Next
From: dmp
Date:
Subject: Re: Problems with BIT datatype and preparedStatment