0

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!

user1040933
  • 277
  • 5
  • 14

1 Answers1

1

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

Community
  • 1
  • 1
Sualeh Fatehi
  • 4,700
  • 2
  • 24
  • 28
  • So how to get the comment for the index ? Even if I have added useInformationSchema=true, the comment from the index is still null. – user1040933 Apr 04 '17 at 09:23
  • Please create a separate StackOverflow question for the index, with example DDL on how to create the index, and I will research for you. – Sualeh Fatehi Apr 04 '17 at 16:22
  • A new question is created: http://stackoverflow.com/questions/43220025/cant-retrieve-comments-for-indexes-when-using-schemacrawler-and-mysql5-7 – user1040933 Apr 05 '17 at 05:25