代码生成器专题(准备一):获取数据库表信息

1、引入hutool工具类 

        
        
            mysql
            mysql-connector-java
            5.1.47
            runtime
        
        
        
        
            cn.hutool
            hutool-all
            ${hutool.version}
        

2、测试代码编写

    @SneakyThrows
    public static void main(String[] args){
        HikariDataSource dataSource = new HikariDataSource();
        dataSource.setJdbcUrl("jdbc:mysql://127.0.0.1:3306/cx-master?autoReconnect=true&useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&zeroDateTimeBehavior=convertToNull&useSSL=false");
        dataSource.setUsername("yonghuming");
        dataSource.setPassword("mima");
        Db db = new Db(dataSource);
        List query = db.query("select table_name tableName, engine, table_comment tableComment, create_time createTime from information_schema.tables where table_schema = (select database())  order by create_time desc");
        Console.error(query);
        dataSource.close();
    }

3、测试结果

代码生成器专题(准备一):获取数据库表信息_第1张图片

 

你可能感兴趣的:(代码生成,java,数据库,mysql)