From: Pete Lewin-Harris <pete@kinomi.com>
To: ben sagal <bsagal@gmail.com>
Cc: Andreas Joseph Krogh <andreak@officenet.no>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: Array paramiters
Date: Tue, 05 Jun 2007 15:55:21 +0100
Message-ID: <46657959.1080206@kinomi.com> (raw)
In-Reply-To: <b72a6e130706050746m37c191e7j3d5ceababe467566@mail.gmail.com>
References: <b72a6e130706040629j4b44ee6g60c15d61b146fc5@mail.gmail.com>
<200706050938.58019.andreak@officenet.no>
<b72a6e130706050723p4c91920ftfeef04417543b104@mail.gmail.com>
<200706051632.31349.andreak@officenet.no>
<b72a6e130706050746m37c191e7j3d5ceababe467566@mail.gmail.com>
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* <andreak@officenet.no
> <mailto:andreak@officenet.no>> 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 <andreak@officenet.no
> <mailto:andreak@officenet.no>>
> 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
> <mailto: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
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: pete@kinomi.com, bsagal@gmail.com, andreak@officenet.no
Subject: Re: Array paramiters
In-Reply-To: <46657959.1080206@kinomi.com>
References: <b72a6e130706040629j4b44ee6g60c15d61b146fc5@mail.gmail.com> <200706050938.58019.andreak@officenet.no> <b72a6e130706050723p4c91920ftfeef04417543b104@mail.gmail.com> <200706051632.31349.andreak@officenet.no> <b72a6e130706050746m37c191e7j3d5ceababe467566@mail.gmail.com> <46657959.1080206@kinomi.com>
* 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