schemacrawler

Can't retrieve the comment for columns but not table when using SchemaCrawler


I am using SchemaCrawler to get the metadata for MySQL5.7 tables using the following code:

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());
}

This is the test table:

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

I can get the column-level comments, but I never can get the table-level comment.

Is there anything that I mis-configured ?

Thanks!


Solution

  • This is an annoyance with the MySQL JDBC driver. You need to set useInformationSchema=true in your JDBC connection URL when creating a connection. For more information, please take a look at the StackOverflow question, Retrieve mysql table comment using DatabaseMetaData.

    Sualeh Fatehi, SchemaCrawler