tags:

views:

34

answers:

2

Can I make the prepared statement

SELECT * FROM STUDENTS WHERE STUDENT_ID IN ?

into

SELECT * FROM STUDENTS WHERE STUDENT_ID IN (1,2,3)

Given that the collection of student ids is a string array.

A: 

I am not clear of your question. I think this link may help you out.

giri
+2  A: 

I think your best solution is going to be generate the in clause dynamically: IN (?,?,?,?) , and then calling preparedStatement.setInt(i + 1, myValues[i]) for each value in your array/collection. The bad news is you will end up with a different preparedStatement for each time you have a different number of values.

See duplicate question: http://stackoverflow.com/questions/178479/alternatives-for-java-sql-preparedstatement-in-clause-issue

gregcase