我使用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';
我可以获得列级评论,但我永远无法获得表级评论。
我有什么错误配置吗?
谢谢!
答案 0 :(得分:1)
这是MySQL JDBC驱动程序的烦恼。创建连接时,需要在JDBC连接URL中设置useInformationSchema=true
。有关详细信息,请查看StackOverflow问题Retrieve mysql table comment using DatabaseMetaData。
Sualeh Fatehi,SchemaCrawler