我想传递一个String数组来一份声明,但它返回此异常:传递一个字符串数组来一份声明中阵列(JDBC + SQLServer的)
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)
我的代码是:
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;
}
异常的线是Array array = this.connection.createArrayOf("VARCHAR", strings.toArray());
这是当我尝试创建阵列。
我已经搜索了如何传递数组,并且每个人都这样做,但似乎不适用于SQLServer。
使用此:'ps.setString(1, “ '逗号', '分开', '价值'”);' –
这个例子只有didatic。在我工作的场景中,我有一百个字符串。 –
@GordThompson这篇文章不谈论sql-server。 –