DuanJiaNing_
2017-04-24 14:17
采纳率: 0%
浏览 1.4k

SQLException After end of result set

samples[cc].setId(set.getInt(Samples.ID));这一句抛了SQL异常:After end of set。
一直找不到原因,不使用 OR 的时候却能正确执行!!!

     public Samples[] getSampleInfo(int[] ids) {
        Samples samples[] = new Samples[ids.length];
        Connection conn = DBMalwareHelper.getConnection();
        StringBuilder builder = new StringBuilder();
        Arrays.stream(ids).filter(i -> i != ids[0]).forEach(i -> builder.append(" OR " + Samples.ID + " = " + i));
        String sql = "SELECT * FROM " + DBMalwareHelper.TABLE_SAMPLES + " WHERE " + Samples.ID + " = " + ids[0] + builder.toString();
        Statement statement = null;
        ResultSet set = null;
        try {
            statement = conn.createStatement();
            set = statement.executeQuery(sql);
            int cc = 0;

            while (set.next()) {
                samples[cc].setId(set.getInt(Samples.ID));
                samples[cc].setPackageName(set.getString(Samples.PACKAGE));
                samples[cc].setType(set.getString(Samples.TYPE));
                samples[cc].setPath(set.getString(Samples.PATH));
                cc++;
            }

            return samples;

        } catch (SQLException e) {
            e.printStackTrace();
            return null;
        } finally {
            DBUtil.closeSetStatConn(conn, set, statement);
        }
    }
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

4条回答 默认 最新

相关推荐 更多相似问题