Mysql遍历数据库所有表、表名、表列名
private List<String> getDBTableName() throws Exception {
List<String> tables = new ArrayList<>();
String sql = "show tables";
PreparedStatement pstmt = new DbUtil().getConn().prepareStatement(sql);
ResultSet rs = uteQuery();
()) {
tables.String(1));
}
return tables;
}
private Map<String, Map<String, String>> getTableColumnName(String tableName) throws Exception {
String sql = "select * from " + tableName;
PreparedStatement pstmt = new DbUtil().getConn().prepareStatement(sql);
ResultSet rs = uteQuery();
ResultSetMetaData rsmd = MetaData();
Map<String, String> tableColumnName_ClassName = new HashMap<>();
for (int i = 0; i < ColumnCount(); i++) {
tableColumnName_ClassName.ColumnName(i+1), ColumnClassName(i+1));
}
Map<String, Map<String, String>> tableColumnNames = new HashMap<>();
tableColumnNames.put(tableName, tableColumnName_ClassName);resultset 遍历
return tableColumnNames;
}
private void getDBAllTablesName_TableColumnsName() throws Exception {
List<Map> DBAllTablesName_TableColumnsName = new ArrayList<>();
List<String> tables = DBTableName();
for (String table : tables) {
DBAllTablesName_TableColumnsName.TableColumnName(table));
}
System.out.println(String());
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。