From: | "ben sagal" <bsagal(at)gmail(dot)com> |
---|---|
To: | "Andreas Joseph Krogh" <andreak(at)officenet(dot)no> |
Cc: | pgsql-jdbc(at)postgresql(dot)org |
Subject: | Re: Array paramiters |
Date: | 2007-06-05 14:23:29 |
Message-ID: | b72a6e130706050723p4c91920ftfeef04417543b104@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-jdbc |
is there any way to do that with a variable amount of elements in the array?
Ben
On 6/5/07, Andreas Joseph Krogh <andreak(at)officenet(dot)no> wrote:
>
> On Monday 04 June 2007 15:29:32 ben sagal wrote:
> > I would like to query data based on the values in a java int array (
> int[]
> > ), using a prepared statement similar to:
> >
> > "SELECT * FROM items WHERE id IN (?)"
> >
> > can anybody advise in have to set the prepared in the statement?
>
> You must generate the query manually, by iterating over your array and add
> '?'
> for each element. Then you need to pass each value of the array to
> setInt(index, array[i]);
>
> --
> Andreas Joseph Krogh <andreak(at)officenet(dot)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 9: In versions below 8.0, the planner will ignore your desire to
> choose an index scan if your joining column's datatypes do not
> match
>
From | Date | Subject | |
---|---|---|---|
Next Message | Andreas Joseph Krogh | 2007-06-05 14:32:31 | Re: Array paramiters |
Previous Message | Heikki Linnakangas | 2007-06-05 14:09:54 | Re: Connection Pool |