1

Is there any java API/java plugin which can generate Database ER diagram when java connection object is provided as input.

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

The API should work with oracle,mysql,postgresql?

I was going through schemacrawler(http://schemacrawler.sourceforge.net/) tool but didint got any API which could do this.

If no API like this is there then let me know how can write my own API? I want to generate ER diagram for all the schema in a database or any specific schema if the schema name is provided as input.

It will be helpful if you show some light on how to achieve this task.

Sualeh Fatehi
  • 4,700
  • 2
  • 24
  • 28
Rajesh
  • 2,934
  • 8
  • 42
  • 71
  • schemacrawler looks promising. Consider using the example, write image to a temp folder and open it with your java application afterwards. – Andreas Dolk Mar 08 '12 at 09:21
  • I didint understood the example given in schema crawler?I mean which API is used in schema crawler to generate ER diagram..and how? can you paste that sample code here?Only I undesrtood this API in schemacrawler final Database database = SchemaCrawlerUtility.getDatabase(connection, options); for (final Schema schema: database.getSchemas()) {} I know this API can be used to crawl through schema,table,column etc – Rajesh Mar 08 '12 at 19:09

2 Answers2

2

This is an old question but in case anyone else stumbles across it as I did when trying to do the same thing I eventually figured out how to generate the ERD using Schemacrawler's java API.

            //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);

This still requires graphviz to be installed and on the path to work.

Woodham
  • 4,053
  • 2
  • 20
  • 15
2

If I understood you question correctly, you might take a look at: JGraph

darijan
  • 9,725
  • 25
  • 38