Re: PreparedStatement for set membership (The IN operator)

From: Daron Ryan <daron(dot)ryan(at)gmail(dot)com>
To: Heikki Linnakangas <heikki(dot)linnakangas(at)enterprisedb(dot)com>, pgsql-jdbc(at)postgresql(dot)org
Subject: Re: PreparedStatement for set membership (The IN operator)
Date: 2011-04-05 12:39:08
Message-ID: 4D9B0D6C.70707@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Thanks Heikki. I have tried using the setArray method but I am still
running into an error.

Exception in thread "main" org.postgresql.util.PSQLException: Unknown
type _INTEGER.
at
org.postgresql.jdbc2.AbstractJdbc2Statement.setArray(AbstractJdbc2Statement.java:2800)
at dictionary.test.Main.main(Main.java:85)

This is the Array implementation I have created.
http://pastebin.com/tkzPRL4A

For baseTypeName I have also tried "int" and received the same error
referring to type _int instead.

This is the code I used to test the implementation
calling code
http://pastebin.com/T1mvADaF

Any idea what I need to do?

On 5/04/2011 5:57 PM, Heikki Linnakangas wrote:
> On 05.04.2011 10:17, Daron Ryan wrote:
>> Hello,
>>
>> I need to use a SELECT statement with varying data for set
>> membership. IE.
>>
>> SELECT link_id
>> FROM links
>> WHERE heading_id IN (?, ?, ?)
>>
>> It won't always be the same number of members in the set. I am using an
>> ordinary statement with an executeQuery call but would prefer to use a
>> PreparedStatement. Is this possible? If so how do I set the values in
>> the set?
>
> You can do "WHERE heading_id = ANY (?)", and pass an array of the ids
> for the parameter.
>

In response to

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Thomas Markus 2011-04-05 12:52:22 Re: PreparedStatement for set membership (The IN operator)
Previous Message Heikki Linnakangas 2011-04-05 08:27:48 Re: PreparedStatement for set membership (The IN operator)