Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 35A1F9FA430 for ; Tue, 28 Nov 2006 05:46:51 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-new, port 10024) with ESMTP id 36779-03 for ; Tue, 28 Nov 2006 05:46:42 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.4 Received: from moutng.kundenserver.de (moutng.kundenserver.de [212.227.126.186]) by postgresql.org (Postfix) with ESMTP id 018099FA2CA for ; Tue, 28 Nov 2006 05:46:45 -0400 (AST) Received: from [83.236.232.74] (helo=[192.168.200.83]) by mrelayeu.kundenserver.de (node=mrelayeu2) with ESMTP (Nemesis), id 0MKwtQ-1GozY00xqj-0007TI; Tue, 28 Nov 2006 10:46:43 +0100 Message-ID: <456C0577.6000100@asci-systemhaus.de> Date: Tue, 28 Nov 2006 10:46:31 +0100 From: =?ISO-8859-15?Q?Ingmar_L=F6tzsch?= User-Agent: Thunderbird 1.5.0.8 (Windows/20061025) MIME-Version: 1.0 To: pgsql-jdbc@postgresql.org Subject: Re: PreparedStatement and TYPE bit References: <456BFE20.8010400@asci-systemhaus.de> In-Reply-To: <456BFE20.8010400@asci-systemhaus.de> X-Enigmail-Version: 0.94.0.0 Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 8bit X-Provags-ID: kundenserver.de abuse@kundenserver.de login:ceb22bc633ad987f91db23b9b4f83498 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200611/157 X-Sequence-Number: 16199 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