JDBC getMetaData将结果集组装到List

 transient List query(Config config, Connection conn, String sql, Object paras[])
        throws SQLException
    {
        List result = new ArrayList();
        PreparedStatement pst = conn.prepareStatement(sql);
        config.dialect.fillStatement(pst, paras);
        ResultSet rs = pst.executeQuery();
        int colAmount = rs.getMetaData().getColumnCount();
        if(colAmount > 1)
        {
            Object temp[];
            for(; rs.next(); result.add(((Object) (temp))))
            {
                temp = new Object[colAmount];
                for(int i = 0; i < colAmount; i++)
                    temp[i] = rs.getObject(i + 1);

            }

        } else
        if(colAmount == 1)
            for(; rs.next(); result.add(rs.getObject(1)));
        DbKit.close(rs, pst);
        return result;
    }

  

原文地址:https://www.cnblogs.com/chenweichu/p/5672953.html