不多说,直接上代码
Connection conn = DriverManager.getConnection(connDo.getUrl(),connDo.getUsername(),connDo.getPassword());
DatabaseMetaData dbm = conn.getMetaData();
ResultSet rs = dbm.getTables(null,null,null,null);//此处是指定筛选条件
while (rs.next()){
String tableName = rs.getString(3);
if(StringUtils.isNotBlank(tableName)){
ResultSet columnRs = dbm.getColumns(null,null,tableName.trim(),null);
List<String> columnList = new ArrayList<>();
while (columnRs.next()){
String columnName = columnRs.getString("COLUMN_NAME");
String typeName = columnRs.getString("TYPE_NAME");
if(StringUtils.isNotBlank(columnName)){
columnList.add(columnName);
}
}
resultMap.put(tableName,columnList);
}
}
注:如果需要获取数据库的其他属性,请自行去ResultSet中找到对应的键值获取即可。