2

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.

Community
  • 1
  • 1
Hector Barbossa
  • 5,506
  • 13
  • 48
  • 70

1 Answers1

2

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?

Community
  • 1
  • 1
Greg Case
  • 3,200
  • 1
  • 19
  • 17