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:46:48 |
Message-ID: | b72a6e130706050746m37c191e7j3d5ceababe467566@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-jdbc |
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(at)officenet(dot)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(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 1: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
> message can get through to the mailing list cleanly
>
From | Date | Subject | |
---|---|---|---|
Next Message | Pete Lewin-Harris | 2007-06-05 14:55:21 | Re: Array paramiters |
Previous Message | Andreas Joseph Krogh | 2007-06-05 14:32:31 | Re: Array paramiters |