Re: ANY subquery and PreparedStatements

Поиск
Список
Период
Сортировка
От Pavel Fokin
Тема Re: ANY subquery and PreparedStatements
Дата
Msg-id 3E537D44.1010209@openvillage.info
обсуждение исходный текст
Ответ на ANY subquery and PreparedStatements  (Felipe Schnack <felipes@ritterdosreis.br>)
Ответы Re: ANY subquery and PreparedStatements
Список pgsql-jdbc
Felipe Schnack wrote:

>  I'm afraid it kind of impossible to use PreparedStatements with the
>"ANY" subquery keyword... For example, if I take this query and prepare
>it:
>  "select * from <table> where <field> any (?)"
>  How can I set my parameter as a list of values, so my query searches
>for for different values of the specified field?
>
>
>
Hello,

You can use a helper variable to store all your values as a string, and
then pass it
to prepared statement, it works for me with IN( ) and I think will work
as well for ANY

example code:

        String categories = "";
        for( int i = 0; i < someCategoryIDs.length; i++ ) {
            if( i > 0 ) { categories = categories + ","; }
            categories = categories + " " + someCategoryIDs[i];
        }

pstmt = connection.prepareStatement( SELECT * FROM catalog WHERE cat_id
IN (" + categories + ") "

Hope it helps

Best Regards,
Pavel Fokin,

Software Engineer,
www.openvillage.info



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

Предыдущее
От: Felipe Schnack
Дата:
Сообщение: ANY subquery and PreparedStatements
Следующее
От: Felipe Schnack
Дата:
Сообщение: Re: ANY subquery and PreparedStatements