Possible Duplicate:
java PreparedStatement
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.
Possible Duplicate:
java PreparedStatement
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.
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: PreparedStatement IN clause alternatives?