How can I retrieve a JDBC ResultSet as an ArrayList?

前端 未结 3 1791
有刺的猬
有刺的猬 2020-12-25 15:40

I\'m doing a query to retrieve a large amount of IDs (integers). Instead of iterating millions of times through the ResultSet and copying everything one-by-one to an ArrayLi

3条回答
  •  醉话见心
    2020-12-25 16:06

    Using the Apache DbUtils library you can easily return a ResultSet as a List of Maps.

    public List query(String query) {
        List result = null;
        try {
            QueryRunner qrun = new QueryRunner();
            result = (List) qrun.query(connection, query, new MapListHandler());
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return result;
    }
    

提交回复
热议问题