From: dmp <danap@ttc-cmc.net>
To: Ermengol Bota <ebota@uoc.edu>
To: pgsql-jdbc@postgresql.org
Subject: Re: Problems with BIT datatype and preparedStatment
Date: Mon, 26 Nov 2012 12:21:20 -0700
Message-ID: <50B3C130.2050400@ttc-cmc.net> (raw)
In-Reply-To: <CABX=gB5B2wyW0oAmugaB2gMQz3LdmASjACjxhGfA38HMgCEq9A@mail.gmail.com>
References: <CABX=gB6H6RqrOd9p38rtiomyqqByovAMpmk6zU5vcJwAHpOovw@mail.gmail.com>
<866187325.381425.1353953148394.JavaMail.root@vilafranca>
<CABX=gB5B2wyW0oAmugaB2gMQz3LdmASjACjxhGfA38HMgCEq9A@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-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 *
> *************************************************
--
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: danap@ttc-cmc.net, ebota@uoc.edu
Subject: Re: Problems with BIT datatype and preparedStatment
In-Reply-To: <50B3C130.2050400@ttc-cmc.net>
References: <CABX=gB6H6RqrOd9p38rtiomyqqByovAMpmk6zU5vcJwAHpOovw@mail.gmail.com> <866187325.381425.1353953148394.JavaMail.root@vilafranca> <CABX=gB5B2wyW0oAmugaB2gMQz3LdmASjACjxhGfA38HMgCEq9A@mail.gmail.com> <50B3C130.2050400@ttc-cmc.net>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox