为了说明目的而简化:
String[] filter = {"foo", "bar"};
String sql = "SELECT * FROM table WHERE column IN ?";
declareParameter(new SqlParameter(Types.ARRAY));
当我执行它时,它不起作用(我得到一个
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Invalid parameter binding(s).
异常。 最佳答案
JDBC不正式支持这种查询,而据我所知,SQL Server也不支持。已经多次讨论了该主题,并提出了几种解决方法:
What is the best approach using JDBC for parameterizing an IN clause?
PreparedStatement IN clause alternatives?
pass variable from java to SQL IN clause
Trouble with PreparedStatement that uses union of selects query and IN CLAUSE
您可能会发现更多内容,因为这确实是一个非常相关但仍未解决的话题。