Using Prepared Statement to pass array of primary key

How can i use the PreparedStatement to send the array (It can be variable depend upon the user selection) of primary keys to database

For example I want prepare statement somthing like this

public Collection findByIds(long[] ids){

String sql = "select * from Person where person_id IN (?)"

PreparedStatement ps = conn.prepareStatement(sql)

ps.setArray();

//

//

//

}

Any example this regard will be appreciated. Database is Oracle

[504 byte] By [sohailn] at [2007-9-26 1:14:21]
# 1
Trying to use a prepared statement with "IN (?)" doesn't work. You will have to use a Statement instead.
DrClap at 2007-6-29 0:31:28 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2
The way I wud do this is to build a comma separated string containing the PKs and just append it to the query....this way you don't even need to have any bind variables to pass the parameters....Wud be a simple query....
prowzen at 2007-6-29 0:31:28 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 3

Hi!

I found your question about sending an Array to a SQL phrase.

(http://forum.java.sun.com/thread.jsp?forum=48&thread=150061)

I have found the same problem.

If you have resolved that problem more elegant than build a SQL phrase dinamic please send me an email with your solution at danctanase@yahoo.com .

Example :

I try to send a parameter to a phrase like this

select * from tableName where fieldName in ?

where ? is like [ "a", "b", "c"] - this collection may have different number of elements.

I don't want to create a SQL phrase dinamic (it's ugly) like this

select from tableName where fieldName = "a" or fieldName = "b" or fieldName = "c"

dantanase at 2007-6-29 0:31:28 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...