我当前正在使用Schemacrawler来收集有关各种数据库的信息。

我遇到的问题是,应用程序在其下运行的用户没有访问每个数据库的权限。如果我尝试检索模式列表:

SchemaCrawlerOptions schemaCrawlerOptions = new SchemaCrawlerOptions();
schemaCrawlerOptions.setSchemaInfoLevel(SchemaInfoLevel.minimum());
schemaCrawlerOptions.setTableTypes(new TableType[] { TableType.table });

Database database = SchemaCrawlerUtility.getDatabase(connection, schemaCrawlerOptions);
database.getSchemas()


...引发SchemaCrawlerException(服务器主体“ ...”在当前安全上下文下无法访问数据库“ ...”。)。有没有办法只获取可访问的数据库(而不必显式声明每个模式名称)?

最佳答案

根据您得到的异常,我将假定您正在使用SQL Server。您需要设置架构包含规则。您可以将其添加到上面的代码段中:

schemaCrawlerOptions.setSchemaInclusionRule(new InclusionRule("schema_name.dbo.*", ""));

10-04 20:02