pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: ben sagal <bsagal@gmail.com>
To: Andreas Joseph Krogh <andreak@officenet.no>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: Array paramiters
Date: Tue, 5 Jun 2007 17:23:29 +0300
Message-ID: <b72a6e130706050723p4c91920ftfeef04417543b104@mail.gmail.com> (raw)
In-Reply-To: <200706050938.58019.andreak@officenet.no>
References: <b72a6e130706040629j4b44ee6g60c15d61b146fc5@mail.gmail.com>
	<200706050938.58019.andreak@officenet.no>

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@officenet.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@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 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
>


view thread (8+ messages)  latest in thread

Message-ID: <b72a6e130706050723p4c91920ftfeef04417543b104@mail.gmail.com>
Permalink:  ../b72a6e130706050723p4c91920ftfeef04417543b104@mail.gmail.com/
Also on:    postgresql.org/message-id/b72a6e130706050723p4c91920ftfeef04417543b104@mail.gmail.com

 · 

reply

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: bsagal@gmail.com, andreak@officenet.no
  Subject: Re: Array paramiters
  In-Reply-To: <b72a6e130706050723p4c91920ftfeef04417543b104@mail.gmail.com>
  References: <b72a6e130706040629j4b44ee6g60c15d61b146fc5@mail.gmail.com> <200706050938.58019.andreak@officenet.no> <b72a6e130706050723p4c91920ftfeef04417543b104@mail.gmail.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