I'm trying to pass an array of Strings to a preparedStatement
, but it's returning this exception:
java.sql.SQLFeatureNotSupportedException: This operation is not supported. at com.microsoft.sqlserver.jdbc.SQLServerConnection.createArrayOf(SQLServerConnection.java:2763) at entity.dao.getRecords(Dao.java:168) at entity.dao.main(Dao.java:227)
My code looks like this:
public List<Record> getRecords() throws SQLException {
String sql = "select * from table where clause in (?)";
PreparedStatement ps = this.connection.prepareStatement(sql);
List<String> strings = new ArrayList<>();
strings.add("string1");
strings.add("string2");
strings.add("string3");
Array array = this.connection.createArrayOf("VARCHAR", strings.toArray());
ps.setArray(1, array);
ResultSet executeQuery = ps.executeQuery();
List<Record> records = new ArrayList<Record>();
Record record;
while (executeQuery.next()) {
// ...
}
return records;
}
The exception line is:
Array array = this.connection.createArrayOf("VARCHAR", strings.toArray());
and occurs when I try to create the array.
I've looked everywhere, like passing an Array to an preparedStatement, and everyone talks to do so, but it does not seem to work with SQLServer.