0

我正在使用 SchemaCrawler 使用以下代码获取 MySQL5.7 表的元数据:

final Connection connection = ...;
final DatabaseSpecificOverrideOptions databaseSpecificOverrideOptions =
                        SchemaCrawlerUtility.matchDatabaseSpecificOverrideOptions(connection);

final SchemaCrawler schemaCrawler = new SchemaCrawler(connection, databaseSpecificOverrideOptions);

final SchemaCrawlerOptions options = new SchemaCrawlerOptions();
options.setSchemaInfoLevel(SchemaInfoLevelBuilder.maximum());
options.setTableInclusionRule(new IncludeAll());
options.setColumnInclusionRule(new IncludeAll());

final Catalog catalog = schemaCrawler.crawl(options);
final Collection<Table> tables = catalog.getTables();

for (Table t : tables) {
    logger.info("Table comment: {}", t.getRemarks());
}

这是测试表:

create table testtable (
    id bigint comment 'key level comment', 
    name varchar(32) comment 'column level comment'
) comment='table level comment';

我可以获得列级评论,但我永远无法获得表级评论。

有什么我配置错误的吗?

谢谢!

4

1 回答 1

1

这是 MySQL JDBC 驱动程序的一个烦恼。创建连接时,您需要useInformationSchema=true在 JDBC 连接 URL 中进行设置。有关更多信息,请查看 StackOverflow 问题Retrieve mysql table comment using DatabaseMetaData

Sualeh Fatehi,SchemaCrawler

于 2017-04-04T03:07:28.393 回答