Java查询MySQL数据库指定数据库中所有表名、字段名、字段类型、字段长度、字段描述
1,查询方法
public static List<Map<String, String>> getColumnInfoByTableName(String databaseName, String databaseUserName, String databaseUserPassword, String tableName){ //指定表 // String sql = "SELECT TABLE_NAME, column_name, DATA_TYPE, COLUMN_TYPE, column_comment FROM information_schema. COLUMNS WHERE TABLE_SCHEMA = '"+databaseName+"' and TABLE_NAME = '"+tableName+"'"; //不指定表 String sql = "SELECT TABLE_NAME, column_name, DATA_TYPE, COLUMN_TYPE, column_comment FROM information_schema. COLUMNS WHERE TABLE_SCHEMA = '"+databaseName+"'"; List<Map<String, String>> columnNameList = getJdbcData("com.mysql.jdbc.Driver", "jdbc:mysql://IP:PORT/databaseName?useUnicode=true&characterEncoding=UTF8", databaseUserName, databaseUserPassword, sql, 1, 5); //结果中的对应关系:column1 -- 表名; column2 -- 字段名; column3 -- 字段类型; column4 -- 字段类型长度; column5 -- 字段描述; return columnNameList; }
2,getJdbcData()方法在https://www.cnblogs.com/cailijuan/p/9964259.html