Rajesh
Rajesh

Reputation: 3014

Required Java API to generate Database ER diagram

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.

Upvotes: 1

Views: 3849

Answers (2)

Woodham
Woodham

Reputation: 4263

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.

Upvotes: 2

darijan
darijan

Reputation: 9775

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

Upvotes: 2

Related Questions