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

时间:2017-07-12 11:21:50

标签: java arrays spring-data

  

伙计们我是java新手我收到此错误请帮助我   我想要做的是获得数组中的结果

        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;
}

1 个答案:

答案 0 :(得分:1)

试试这个

statement.setArray(1, array);

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

修改

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

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