Received: from localhost (maia-4.hub.org [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 2BA7F9FB662 for ; Tue, 5 Jun 2007 11:32:42 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 59292-05-2 for ; Tue, 5 Jun 2007 11:32:34 -0300 (ADT) X-Greylist: delayed 06:53:18.760548 by SQLgrey-1.7.4 Received: from ns1.officenet.no (ns1.officenet.no [193.212.174.3]) by postgresql.org (Postfix) with ESMTP id 442799FBB6A for ; Tue, 5 Jun 2007 11:32:30 -0300 (ADT) Received: from [85.112.130.182] (helo=krogh-laptop.local) by ns1.officenet.no with esmtpsa (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.62) (envelope-from ) id 1Hva5B-0008KP-Dp for pgsql-jdbc@postgresql.org; Tue, 05 Jun 2007 16:32:28 +0200 From: Andreas Joseph Krogh Organization: OfficeNet AS To: pgsql-jdbc@postgresql.org Subject: Re: Array paramiters Date: Tue, 5 Jun 2007 16:32:31 +0200 User-Agent: KMail/1.9.7 References: <200706050938.58019.andreak@officenet.no> In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Message-Id: <200706051632.31349.andreak@officenet.no> 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/11 X-Sequence-Number: 17073 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 =3D new int[]{1,2,3}; StringBuffer sb =3D new StringBuffer(); sb.append("SELECT * FROM items WHERE id IN(").append(generateCSV("?",=20 num.length)).append(")"); for (int i =3D 0; i < num.length; i++) { ps.setInt(i, num[i]); } ps.executeQuery(); The generateCSV-method must return a comma-separated String, in this case t= he=20 String "?,?,?", because num-array has length=3D=3D3. then num-array can be of any lenth you want. =2D-=20 Andreas Joseph Krogh Senior Software Developer / Manager =2D-----------------------+---------------------------------------------+ OfficeNet AS | The most difficult thing in the world is to | Karenslyst All=C3=A9 11 | know how to do a thing and to watch | PO. Box 529 Sk=C3=B8yen | somebody else doing it wrong, without | 0214 Oslo | comment. | NORWAY | | Tlf: +47 24 15 38 90 | | =46ax: +47 24 15 38 91 | | Mobile: +47 909 56 963 | | =2D-----------------------+---------------------------------------------+