gpt4 book ai didi

java - PreparedStatement 类型中的方法 setArray(int, Array) 不适用于参数 (String, String[])

转载 作者:行者123 更新时间:2023-11-30 06:37:00 25 4
gpt4 key购买 nike

Guys i am new to java i am getting this error please help me out what i am trying to do is get result in array

        public List<DeviceDetail> list(String[] deviceIds) throws Exception {
List<DeviceDetail> appList = new ArrayList<>();
Connection conn =null;
CallableStatement statement = conn.prepareCall("{call
Application_List(?)}");
statement.setArray("Deviceid",deviceIds);
boolean isResultSet = statement.execute();
if (isResultSet) {
try (ResultSet rs = statement.getResultSet()) {
while (rs.next()) {
DeviceDetail dd = new DeviceDetail();
dd.setDeviceId(rs.getString("DeviceId"));
dd.setToken(rs.getString("Token"));
dd.setDeviceType(rs.getString("DeviceType"));
dd.setCreatedBy(rs.getString("CreatedBy"));
dd.setCreatedTime(rs.getTimestamp("CreatedTime"));
dd.setStatus(rs.getBoolean("Status"));
appList.add(dd);
}
}
}
return appList;
}

最佳答案

试试这个

statement.setArray(1, array);

您需要将通配符位置指定为Integer而不是String

编辑

使用以下方法创建java.sql.Array

Array array = conn.createArrayOf("VARCHAR", deviceIds);

关于java - PreparedStatement 类型中的方法 setArray(int, Array) 不适用于参数 (String, String[]),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45056291/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com