Re: Problems with BIT datatype and preparedStatment

Поиск
Список
Период
Сортировка
От Ermengol Bota
Тема Re: Problems with BIT datatype and preparedStatment
Дата
Msg-id CABX=gB5B2wyW0oAmugaB2gMQz3LdmASjACjxhGfA38HMgCEq9A@mail.gmail.com
обсуждение исходный текст
Ответ на Problems with BIT datatype and preparedStatment  (Ermengol Bota <ebota@uoc.edu>)
Ответы Re: Problems with BIT datatype and preparedStatment  (dmp <danap@ttc-cmc.net>)
Список 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 по дате отправления:

Предыдущее
От: dmp
Дата:
Сообщение: Re: Problems with BIT datatype and preparedStatment
Следующее
От: dmp
Дата:
Сообщение: Re: Problems with BIT datatype and preparedStatment