Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id AE5799FB56B for ; Tue, 5 Jun 2007 12:25:46 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-maia, port 10024) with ESMTP id 48872-05 for ; Tue, 5 Jun 2007 12:25:35 -0300 (ADT) X-Greylist: delayed 00:29:36.096513 by SQLgrey-1.7.5 Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id F15559FBDEE for ; Tue, 5 Jun 2007 12:25:31 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.3 Received: from oasiscamden.mezzonet.net (81-171-175-150.oasiscamden.mezzonet.net [81.171.175.150]) by svr4.postgresql.org (Postfix) with ESMTP id 9D5CD5AF025 for ; Tue, 5 Jun 2007 14:55:51 +0000 (GMT) Received: from [192.168.128.104] ([10.0.17.100]) by oasiscamden.mezzonet.net (8.12.11.20060308/8.12.11) with ESMTP id l55EtLoO014231; Tue, 5 Jun 2007 15:55:21 +0100 Message-ID: <46657959.1080206@kinomi.com> Date: Tue, 05 Jun 2007 15:55:21 +0100 From: Pete Lewin-Harris User-Agent: Thunderbird 2.0.0.0 (Windows/20070326) MIME-Version: 1.0 To: ben sagal Cc: Andreas Joseph Krogh , pgsql-jdbc@postgresql.org Subject: Re: Array paramiters References: <200706050938.58019.andreak@officenet.no> <200706051632.31349.andreak@officenet.no> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.001 tagged_above=0 required=5 tests=BAYES_50=0.001 X-Spam-Level: X-Archive-Number: 200706/15 X-Sequence-Number: 17077 If I undestand you correctly you're looking for something like (in pseudo-non-working-code): int[] num = new int[]{1,2,3}; PreparedStatement ps = new PreparedStatement( "SELECT * FROM items WHERE id IN ?"); ps.setArray(num); ps.executeQuery(); If this is the case, then I'm pretty sure your answer's no. I've wanted this a few times and haven't found anything. Your best answer is what Andreas suggested. cheers, Pete ben sagal wrote: > I would ideally like to use a prepared statement, in which i can on each > execution insert a different array? the method u suggest will not allow > use of a prepared statement. > > thanks Ben > > > On 6/5/07, *Andreas Joseph Krogh* > wrote: > > On Tuesday 05 June 2007 16:23:29 ben sagal wrote: > > is there any way to do that with a variable amount of elements in > the > > array? > > I'm not quite sure what you mean? > Say you have the following: > > int[] num = new int[]{1,2,3}; > StringBuffer sb = new StringBuffer(); > sb.append("SELECT * FROM items WHERE id IN(").append(generateCSV("?", > num.length)).append(")"); > for (int i = 0; i < num.length; i++) { > ps.setInt(i, num[i]); > } > ps.executeQuery(); > > The generateCSV-method must return a comma-separated String, in this > case the > String "?,?,?", because num-array has length==3. > > then num-array can be of any lenth you want. > > -- > Andreas Joseph Krogh > > Senior Software Developer / Manager > ------------------------+---------------------------------------------+ > OfficeNet AS | The most difficult thing in the world is to | > Karenslyst Allé 11 | know how to do a thing and to watch | > PO. Box 529 Skøyen | somebody else doing it wrong, without | > 0214 Oslo | comment. | > NORWAY | | > Tlf: +47 24 15 38 90 | | > Fax: +47 24 15 38 91 | | > Mobile: +47 909 56 963 | | > ------------------------+---------------------------------------------+ > > ---------------------------(end of broadcast)--------------------------- > TIP 1: if posting/reading through Usenet, please send an appropriate > subscribe-nomail command to majordomo@postgresql.org > so that your > message can get through to the mailing list cleanly > > -- Pete Lewin-Harris Senior Software Engineer Tel: 020 7788 4388 Email: pete@kinomi.com