0

Simplified for illustrative purposes:

String[] filter = {"foo", "bar"};
String sql = "SELECT * FROM table WHERE column IN ?";
declareParameter(new SqlParameter(Types.ARRAY));

This doesn't work when I execute it (I get a java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Invalid parameter binding(s). exception.

2 Answers 2

1

JDBC doesn't support this kind of query officially and SQL Server doesn't either as far as I know. This topic has been discussed on SO many times and several workarounds have been proposed:

You can probably find many more as it is indeed a very relevant yet still open topic.

Sign up to request clarification or add additional context in comments.

Comments

0

I am not sure about MS SQL Server. But such a code wouldn't work on oracle DB. In oracle, we cannot pass a java array to an IN clause. The way to work around that limitation is to construct a PL/SQL function that converts a list of strings into a table, something like stringToTable. Then pass a concatenated string as a parameter.

Again, this answer is applicable for Oracle DB; It might not work on MS SQL server.

2 Comments

I did not say that it cannot be done in oracle. I just said that you cannot directly pass a java array into a PL?SQL array without doing some intermediate processing or mapping. Your links provide one way to do it. The answer I gave is another way that I have done in my code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.