I'm trying to pass an String array to a prepared statement, 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:
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 the exception is Array array = this.connection.createArrayOf("VARCHAR", strings.toArray());
it's when i try to create the Array.
I already searched how to pass the Array and everybody tells to do like this, but seems to don't work with SQLServer.