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.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I think your best solution is going to be generate the in clause dynamically:
IN (?,?,?,?), and then callingpreparedStatement.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?