0

当我尝试使用 SchemaCrawler API 从 SQL Server 数据库中检索存储过程时,出现以下错误:

12:28:07.427 [main] INFO  schemacrawler.crawl.SchemaCrawler - Retrieving routines
12:28:07.767 [main] WARN  schemacrawler.crawl.RoutineRetriever - JDBC driver does not support retrieving functions
java.lang.AbstractMethodError: null
    at net.sourceforge.jtds.jdbc.JtdsDatabaseMetaData.getFunctions(JtdsDatabaseMetaData.java:3570) ~[jtds-1.3.1.jar:1.3.1]
    at schemacrawler.crawl.RoutineRetriever.retrieveFunctions(RoutineRetriever.java:175) ~[schemacrawler-14.02.02.jar:na]
    at schemacrawler.crawl.SchemaCrawler.crawlRoutines(SchemaCrawler.java:214) [schemacrawler-14.02.02.jar:na]
    at schemacrawler.crawl.SchemaCrawler.crawl(SchemaCrawler.java:564) [schemacrawler-14.02.02.jar:na]
    at schemacrawler.utility.SchemaCrawlerUtility.getCatalog(SchemaCrawlerUtility.java:49) [schemacrawler-14.02.02.jar:na]
    at schemacrawler.utility.SchemaCrawlerUtility.getCatalog(SchemaCrawlerUtility.java:57) [schemacrawler-14.02.02.jar:na]
    at com.expedia.cgs.db.ExportScripts.main(ExportScripts.java:41) [classes/:na]

jtds 驱动支持DatabaseMetaData.getProcedures()但不支持DatabaseMetaData.getFunctions(). 有解决方法吗?

更新:这是我的代码:

import java.sql.Connection;
import java.sql.SQLException;
import javax.sql.DataSource;
import org.slf4j.bridge.SLF4JBridgeHandler;
import schemacrawler.schema.Catalog;
import schemacrawler.schema.Column;
import schemacrawler.schema.Routine;
import schemacrawler.schema.Schema;
import schemacrawler.schema.Table;
import schemacrawler.schema.View;
import schemacrawler.schemacrawler.DatabaseConnectionOptions;
import schemacrawler.schemacrawler.RegularExpressionInclusionRule;
import schemacrawler.schemacrawler.SchemaCrawlerException;
import schemacrawler.schemacrawler.SchemaCrawlerOptions;
import schemacrawler.schemacrawler.SchemaInfoLevelBuilder;
import schemacrawler.utility.SchemaCrawlerUtility;

public class ExportScripts {

    public static void main(String[] args) throws SchemaCrawlerException, SQLException {
        SLF4JBridgeHandler.removeHandlersForRootLogger();
        SLF4JBridgeHandler.install();

        // Create a database connection
        final DataSource dataSource = new DatabaseConnectionOptions("jdbc:sqlserver://myDatabase;appName=SchemaCrawler;useCursors=true");
        final Connection connection = dataSource.getConnection("username", "password");

        // Create the options
        final SchemaCrawlerOptions options = new SchemaCrawlerOptions();
        // Set what details are required in the schema - this affects the
        // time taken to crawl the schema
        options.setSchemaInfoLevel(SchemaInfoLevelBuilder.standard());
        options.setRoutineInclusionRule(new RegularExpressionInclusionRule("ContentGeneration\\.dbo.*"));
        options.setSchemaInclusionRule(new RegularExpressionInclusionRule("ContentGeneration\\.dbo.*"));

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

        for (final Schema schema : catalog.getSchemas()) {
            System.out.println(schema);
            for (final Routine routine : catalog.getRoutines()) {
                System.out.println("r--> " + routine);
                System.out.println("definition: " + routine.getDefinition());
            }
            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() + ")");
                }
            }
        }
    }
}
4

1 回答 1

0

以下是如何获得对 Microsoft SQL Server 的完整 SchemaCrawler 支持。

  1. 在 Maven 项目中包含支持 Microsoft SQL Server 的 SchemaCrawler jar。

<dependency> <groupId>us.fatehi</groupId> <artifactId>schemacrawler-sqlserver</artifactId> <version>14.02.02</version> </dependency>

  1. 使用与下面类似的代码。

    final DatabaseSystemConnector dbSystemConnector = new SqlServerDatabaseConnector().getDatabaseSystemConnector();

    final DatabaseSpecificOverrideOptions databaseSpecificOverrideOptions = dbSystemConnector.getDatabaseSpecificOverrideOptionsBuilder().toOptions();

    final SchemaCrawlerOptions schemaCrawlerOptions = new SchemaCrawlerOptions(); schemaCrawlerOptions.setSchemaInfoLevel(InfoLevel.maximum.buildSchemaInfoLevel());

    最终目录目录 = SchemaCrawlerUtility.getCatalog(getConnection(), databaseSpecificOverrideOptions, schemaCrawlerOptions);

  2. 循环遍历例程,并用于Routine.getDefinition()获取定义。

Sualeh Fatehi,SchemaCrawler

于 2015-08-18T00:37:41.643 回答