2012-03-08 37 views
1

是否有任何Java API/java插件可以在提供java連接對象作爲輸入時生成數據庫ER圖。需要Java API來生成數據庫ER圖

例:InputSream generateDatabaseERDiagram(java connection object)// where inputsream will point to generated ER diagram image

的API應該與Oracle,MySQL和PostgreSQL工作?

我正在通過schemacrawler(http://schemacrawler.sourceforge.net/)工具,但沒有得到任何API可以做到這一點。

如果沒有這樣的API,那麼讓我知道如何編寫我自己的API?如果模式名稱作爲輸入提供,我想爲數據庫中的所有模式或任何特定模式生成ER圖。

如果您瞭解如何完成此任務,將會有所幫助。

+0

schemacrawler看起來很有前途。考慮使用該示例,將圖像寫入臨時文件夾,然後在您的Java應用程序中打開它。 – 2012-03-08 09:21:35

+0

我沒有理解模式爬蟲中給出的例子嗎?我的意思是模式爬蟲使用哪個API來生成ER圖。以及如何?你可以在那裏粘貼這個示例代碼嗎?只有我不喜歡schemacrawler中的這個API final Database database = SchemaCrawlerUtility.getDatabase(connection, options); (最終Schema模式:database.getSchemas()) {}我知道這個API可以用於通過模式,表,列等進行爬網 – Rajesh 2012-03-08 19:09:15

回答

2

如果我理解你的問題正確的話,你可能會看一看:試圖做我終於想通了同樣的事情時JGraph

2

這是一個老問題,但在越過它萬一別人絆倒像我一樣如何使用Schemacrawler的Java API生成ERD。

  //Get your java connection however 
      Connection conn = DriverManager.getConnection("DATABASE URL"); 
      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()); 
      // you can exclude/include objects using the options object e.g. 
      //options.setTableInclusionRule(new RegularExpressionExclusionRule(".*qrtz.*||.*databasechangelog.*")); 

      GraphExecutable ge = new GraphExecutable(); 

      ge.setSchemaCrawlerOptions(options); 

      String outputFormatValue = GraphOutputFormat.png.getFormat(); 

      OutputOptions outputOptions = new OutputOptions(outputFormatValue, new File("database.png").toPath()); 

      ge.setOutputOptions(outputOptions); 

      ge.execute(conn); 

這仍然需要graphviz被安裝和工作的路徑。