Re: Using SELECT IN with prepared statement

Поиск
Список
Период
Сортировка
От Ingmar Lötzsch
Тема Re: Using SELECT IN with prepared statement
Дата
Msg-id 4919367E.9030306@asci-systemhaus.de
обсуждение исходный текст
Ответ на Using SELECT IN with prepared statement  (Tiago Alves <talves@tapestry.pt>)
Ответы Re: Using SELECT IN with prepared statement  (Tiago Alves <talves@tapestry.pt>)
Список pgsql-jdbc
Hello,

you can use another syntax

WHERE userid = ANY (?)

and call PreparedStatement.setArray(). That means, you have to provide
an instance of java.sql.Array as parameter. For this purpose you can
implement this interface (It's not too difficult, I've done this.) or
use Connection.createArrayOff(). The last is available dependent on the
JDBC-Library you use. I have not tried it yet.

One advantage of ANY instead of IN is, that you can pass an empty array
without causing a SQL syntax error.

Ingmar

Tiago Alves schrieb:
> Greetings!
>
> Sorry if you answer this before, I couldn't find it.
>
> I want to do something like:
>
> PreparedStatement ps = connection.prepareStatement("select * from users
> where userid in ?");
> ps.setSomething(anIntArray);
>
> Is this possible? How?
>
> Thanks.
> Tiago A.
>


В списке pgsql-jdbc по дате отправления:

Предыдущее
От: Alexander Panzhin
Дата:
Сообщение: Re: Using SELECT IN with prepared statement
Следующее
От: "Shawn Chasse"
Дата:
Сообщение: Re: Pgsql jdbc driver 8.3 Build 603: Commit deadlock