pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ingmar Lötzsch <iloetzsch@asci-systemhaus.de>
To: pgsql-jdbc@postgresql.org
Subject: Re: PreparedStatement and TYPE bit
Date: Tue, 28 Nov 2006 10:46:31 +0100
Message-ID: <456C0577.6000100@asci-systemhaus.de> (raw)
In-Reply-To: <456BFE20.8010400@asci-systemhaus.de>
References: <456BFE20.8010400@asci-systemhaus.de>

Ingmar Lötzsch schrieb:
> Hallo,
> 
> how can I use PreparedStatement to insert or update columns of type
> bit(n), varbit, ...?
> 
> I have never figoured out the right way. In former versions of the
> JDBC-Driver I used setString() as shown below or constructed the whole
> query string and used Statement.
> 
> String sql =
> "...
> WHERE f1.verkehrstage & B? <> 0::bit(384)
> ...";
> 
> PreparedStatement pstmt_select1 = con.prepareStatement(sql);
> 
> BigInteger mybits = ...
> 
> // padding bits 0 on the left up to 384 (type bit(384))
> String querybits = mybits.or(this.bit384).toString(2).substring(1);

mybits has max. 384 bits. this.bit384 is a BigInteger with the value of
2^384. Thats why mybits.or(this.bit384) results in a BigInteger with
exact 385 bits with 1 on the most significant position and
mybits.or(this.bit384).toString(2).substring(1) is a "bitstring" with
exact 384 bits.

> pstmt_select1.setString(1, querybits);
> ...
> ResultSet rs = pstmt_select1.executeQuery();
> 
> This does not work in versions 8.x.
> 
> Thank you



view thread (3+ messages)  latest in thread

Message-ID: <456C0577.6000100@asci-systemhaus.de>
Permalink:  ../456C0577.6000100@asci-systemhaus.de/
Also on:    postgresql.org/message-id/456C0577.6000100@asci-systemhaus.de

 · 

reply

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: iloetzsch@asci-systemhaus.de
  Subject: Re: PreparedStatement and TYPE bit
  In-Reply-To: <456C0577.6000100@asci-systemhaus.de>
  References: <456BFE20.8010400@asci-systemhaus.de> <456C0577.6000100@asci-systemhaus.de>

* 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