Re: Problems with BIT datatype and preparedStatment

From: dmp <danap(at)ttc-cmc(dot)net>
To: Ermengol Bota <ebota(at)uoc(dot)edu>, pgsql-jdbc(at)postgresql(dot)org
Subject: Re: Problems with BIT datatype and preparedStatment
Date: 2012-11-26 19:21:20
Message-ID: 50B3C130.2050400@ttc-cmc.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Ermengol Bota wrote:
> 2012/11/26 dmp <danap(at)ttc-cmc(dot)net <mailto:danap(at)ttc-cmc(dot)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 *
> *************************************************

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message pavel.arnost 2012-12-06 17:04:41 Statement.setQueryTimeout() with autoCommit=false
Previous Message Ermengol Bota 2012-11-26 18:43:00 Re: Problems with BIT datatype and preparedStatment