I have a List of Strings that I want to set as a parameter in a preparedstatement. This question and answer here, makes it look easy:
How to use an arraylist as a prepared statement parameter
Well, not really easy. There is still the conversion of a List, to an SQL-Array, which I found easiest to do by creating a String[] in between.
Below is my code:
PreparedStatement s = con.prepareStatement("SELECT * FROM Table WHERE Country IN ? ");
String[] countryArray = new String[countryListObject.size()];
countryArray = countryListObject.toArray(countryArray);
Array cArray = con.createArrayOf("VARCHAR", countryArray); //<--- Throws the exception
s.setArray(1, cArray);
This answer Seems to adress a similar problem, but I can't really understand how this helped solve anything. The answer is ambigous at best, stating only that:
Basically what you are wanting to do is not directly possible using a PreparedStatement.
I've come to learn from the API Documentation that this exception is thrown if the JDBC driver does not support this method. I'm running a com.microsoft.sqlserver sqljdbc4 version 3.0. I am trying to see which versions do and don't support setArray, but I can't find the information. It is probably right in front of me, but I would really appreciate a little help on this.
How can I figure out if my JDBC's do support setArray()?