schemacrawlar无法打印出表名

时间:2016-08-11 03:34:56

标签: schemacrawler

打击代码只打印出数据库名称,为什么?

public static void main(final String[] args) throws Exception
    {
        // Create a database connection
        final DataSource dataSource = new DatabaseConnectionOptions("jdbc:mysql://localhost:3306/target_db");
        final Connection connection = dataSource.getConnection("root", "password");

        // Create the options
        final SchemaCrawlerOptions options = new SchemaCrawlerOptions();
        options.setSchemaInfoLevel(SchemaInfoLevelBuilder.standard());

        options.setTableTypes(Lists.newArrayList("BASE TABLE","TABLE","VIEW"));
        options.setRoutineInclusionRule(new ExcludeAll());
        options.setSchemaInclusionRule(new RegularExpressionInclusionRule("target_db"));
        options.setTableNamePattern("*");

        // Get the schema definition
        final Catalog catalog = SchemaCrawlerUtility.getCatalog(connection, options);

        for (final Schema schema : catalog.getSchemas())
        {
            System.out.print("c--> " + schema.getCatalogName() + "\n");

            for (final Table table : catalog.getTables(schema))
            {

                System.out.print("o--> " + table);
                if (table instanceof View)
                {
                    System.out.println(" (VIEW)");
                } else
                {
                    System.out.println();
                }

                for (final Column column : table.getColumns())
                {
                    System.out.println("     o--> " + column + " (" + column.getColumnDataType() + ")");
                }
            }
        }
    }
}

奇怪的是,

./schemacrawler.sh -server=mysql -database=target_db -user=root -password=password -infolevel=ALL -command=schema

将输出表格和相应的列。

更新:我的配置

 schemacrawler-14.09.03-main
  Ubuntu 16.04 64bit
  MariaDB 10.2.1-MariaDB-1~xenial
  (I assumed mariadb may not be supported yet,so switch between blow two drivers,but neither works)
  mysql-connector-java-6.0.3
 mariadb-java-client-1.4.6

1 个答案:

答案 0 :(得分:0)

最后,我想通了:

 options.setTableTypes(Lists.newArrayList("BASE TABLE","TABLE","VIEW","UNKNOWN"));

警告:对于MariaDB,表类型为" UNKNOWN"