2017-10-12 109 views
0

我正在使用Eclipse,SQLite数据库和Hibernate。我想在我的项目中使用SchemaCrawler,已经有了sqlite-jdbc库。我的目标是比较使用两个数据库的SchemaCrawler结构。但我甚至无法连接到我的第一个数据库。我使用此代码:SchemaCrawler需要哪些JAR文件?

public class SchemaConroller { 

    public SchemaConroller() { 

     SchemaCrawlerOptions options = new SchemaCrawlerOptions(); 
     options.setSchemaInfoLevel(SchemaInfoLevelBuilder.standard()); 


     try { 
      Connection conn = getConnection(); 
      Catalog catalog = SchemaCrawlerUtility.getCatalog(conn, options); 
      for (Schema schema : catalog.getSchemas()) { 
       System.out.println(schema); 
       for (Table table : catalog.getTables(schema)) { 
        System.out.print("o--> " + table); 
        for (Column column : table.getColumns()) { 
         System.out.println("  o--> " + column); 
        } 
       } 
      } 
     } catch (Exception e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 
    } 

    private static Connection getConnection() throws SchemaCrawlerException, SQLException, ClassNotFoundException { 
     String dbPath = "src/home/accounting/DB/myDatabase.sqlite"; 
     Class.forName("org.sqlite.JDBC"); 
     Connection c = DriverManager.getConnection("jdbc:sqlite:" + dbPath); 
     return c; 
    } 
} 

我总是得到错误:

Oct 12, 2017 1:31:50 PM schemacrawler.utility.SchemaCrawlerUtility matchDatabaseSpecificOverrideOptions 
INFO: Using database plugin for 
Oct 12, 2017 1:31:50 PM schemacrawler.utility.TypeMap <init> 
WARNING: Could not obtain data type map from connection 
java.lang.NullPointerException 
    at org.sqlite.jdbc3.JDBC3Connection.getTypeMap(JDBC3Connection.java:90) 
    at schemacrawler.utility.TypeMap.<init>(TypeMap.java:116) 
    at schemacrawler.crawl.RetrieverConnection.<init>(RetrieverConnection.java:194) 
    at schemacrawler.crawl.SchemaCrawler.crawl(SchemaCrawler.java:870) 
    at schemacrawler.utility.SchemaCrawlerUtility.getCatalog(SchemaCrawlerUtility.java:75) 
    at home.accounting.controller.SchemaConroller.<init>(SchemaConroller.java:35) 
    at home.accounting.DA.DBCheck.start(DBCheck.java:44) 
    at home.accounting.MainApp.start(MainApp.java:83) 
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863) 
    at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326) 
    at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294) 
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95) 
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method) 
    at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191) 
    at java.lang.Thread.run(Thread.java:748) 

我下载schemacrawler.jar从here。难道还需要其他任何罐子吗?

+0

需要不**字符串DBPATH = “SRC /家庭/会计/ DB/myDatabase.sqlite” 物理路径; ** – 2017-10-12 12:57:09

+0

我也试图与这一个:'最终数据源数据源=新的DatabaseConnectionOptions(“jdbc:sqlite:src/home/accounting/DB/myDatabase.sqlite”); \t \t return dataSource.getConnection(“brunduk”,“brunduk”);'没有区别。 – Alyona

回答

1

Alyona,您可以忽略您在问题中发布的日志中的警告。 sqlite-jdbc jar不完全符合JDBC标准,所以你必须非常特别地使用该jar版本。请使用仅适用于SchemaCrawler distribution的版本3.7.8。另外,您需要使用与您正在使用的SchemaCrawler版本相对应的schemacrawler-sqlite jar

Sualeh Fatehi,SchemaCrawler

+0

它是与SchemaCrawler 14.16.04版本兼容还是应该切换到以前版本的SchemaCrawler? – Alyona

+0

我尝试使用它与上面提到的版本,我仍然收到错误'在org.sqlite.Conn.getTypeMap(Conn.java:419)',但至少它现在工作!它给了我我的数据库结构。我对我的问题发表评论https://stackoverflow.com/questions/46706970/how-to-compare-two-database-structures它不是这个副本,因为它要求完全不同的事情。你能帮我解答一下吗?至于这个,我的问题已经解决了。 – Alyona