Skip site navigation (1) Skip section navigation (2)

Re: PreparedStatement and TYPE bit

From: Ingmar Lötzsch <iloetzsch(at)asci-systemhaus(dot)de>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: PreparedStatement and TYPE bit
Date: 2006-11-28 09:46:31
Message-ID: 456C0577.6000100@asci-systemhaus.de (view raw or flat)
Thread:
Lists: pgsql-jdbc
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

In response to

Responses

pgsql-jdbc by date

Next:From: alfranio correia juniorDate: 2006-11-28 14:04:32
Subject: PLPG
Previous:From: Altaf MalikDate: 2006-11-28 09:46:27
Subject: Re: Postgres Server collapse

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group