这里是检索数据库表的源代码:
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;