0
I am 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 is 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 line of exception is:
Array array = this.connection.createArrayOf("VARCHAR", strings.toArray());
and occurs when I try to create the array.
I’ve looked everywhere, how to pass an Array to a preparedStatement, and everyone talks to do so, but it doesn’t seem to work with Sqlserver.
Henrique, you don’t have to quote the tags in the title.
– user28595