0

I would like to do the following

private List<Number> getIds(List<String> names) {
    String query = "SELECT id FROM months WHERE name IN (?)";
            ...
    }

How can I pass my List<String> names to the '?' in the query above? I am looking for a dynamic solution as the size of the given list will vary.

I am using Spring 3.0 with Oracle 11.2.0.2.

Thanks.

davhab
  • 805
  • 2
  • 9
  • 17
  • 2
    possible duplicate of [How do you write the SQL for a PreparedStatement using a WHERE x IN clause?](http://stackoverflow.com/questions/4381791/how-do-you-write-the-sql-for-a-preparedstatement-using-a-where-x-in-clause) – Thilo Aug 16 '12 at 09:15
  • also http://stackoverflow.com/questions/178479/preparedstatement-in-clause-alternatives?lq=1 – Thilo Aug 16 '12 at 09:16
  • Or using Spring JdbcTemplates: http://stackoverflow.com/questions/1981683/how-to-generate-a-dynamic-in-sql-list-through-spring-jdbctemplate?lq=1 – Thilo Aug 16 '12 at 09:19

1 Answers1

0

Why don't you use a database function which returns a collection and call the function from Java using CallableStatement?

By doing so you could eliminate the problem of passing multiple values to IN condition.

Regards

Jacob
  • 14,463
  • 65
  • 207
  • 320