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

From dmp
Subject Re: Problems with BIT datatype and preparedStatment
Date
Msg-id 50B3C130.2050400@ttc-cmc.net
Whole thread Raw
In response to Re: Problems with BIT datatype and preparedStatment  (Ermengol Bota <ebota@uoc.edu>)
List pgsql-jdbc
Ermengol Bota wrote:
> 2012/11/26 dmp <danap@ttc-cmc.net <mailto: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...
>
> http://archives.postgresql.__org/pgsql-patches/2003-06/__msg00402.php
> <http://archives.postgresql.org/pgsql-patches/2003-06/msg00402.php>
>
> btw, which forum do you refer?

This forum, jdbc.postgresql. The search you turned up for the example given
appears to be from the server forum. The patch you refer to:

/projects/cvsroot/pgsql-server/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Statement.java,v

seems to be for the server not the JDBC code. It is also very old, 2003,
while might have worked then does not now it appear. There has many changes
I suspect in the last 8,9 years.

>     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.

The documentation
http://www.postgresql.org/files/documentation/pdf/9.2/postgresql-9.2-A4.pdf I
think chapter 8 discusses data types in
PostgreSQL. The manual is your friend.

danap.

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



pgsql-jdbc by date:

Previous
From: Ermengol Bota
Date:
Subject: Re: Problems with BIT datatype and preparedStatment
Next
From: Zsolt Kúti
Date:
Subject: Re: The column name was not found in this ResultSet