我从数据库中检索表时如何限制resultSet大小

时间:2016-07-12 10:32:15

标签: jdbc

这里是检索数据库表的源代码:

    DatabaseMetaData dmd = connection.getMetaData();
    ResultSet resultSet = dmd.getTables(connection.getCatalog(), null, null, TABLE_TYPES);
    while(resultSet.next()){
        treeMap.put(resultSet.getString(TABLE_NAME), new ArrayList<>());
        ResultSet fields = dmd.getColumns(null, null, resultSet.getString(TABLE_NAME), null);
        while(fields.next()){
            treeMap.get(resultSet.getString(TABLE_NAME)).add(fields.getString("COLUMN_NAME"));
        }
    }
    connection.close();
    treeMap.forEach((s, strings) -> System.out.println(s+" -> "+String.join(",",strings)));
    return treeMap;

0 个答案:

没有答案