Setting Array in preparedstatement, throws a java.sql.SQLFeatureNotSupportedException

﹥>﹥吖頭↗ 提交于 2019-12-24 01:27:14

问题


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()?

来源:https://stackoverflow.com/questions/36282752/setting-array-in-preparedstatement-throws-a-java-sql-sqlfeaturenotsupportedexce

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!