Over a million developers have joined DZone.

SchemaSpy - Excellent Database Graphs for Free!

DZone's Guide to

SchemaSpy - Excellent Database Graphs for Free!

· Java Zone
Free Resource

Bitbucket is for the code that takes us to Mars, decodes the human genome, or drives your next car. What will your code do? Get started with Bitbucket today, it's free.

A lot of Java projects have quite complex database schemas in the backend. Although, using object-relational mapping it can be useful to have a deeper understanding of such a schema, e.g. when writing CRUD tests.

For me the visualization of table relations is quite important, besides the table attributes. There are a lot of entity relationship modeling tools out there, doing a pretty good job. But, most of them are also quite expensive.

I did a search for something OpenSource and found some tools from the mySQL community. Although, these should support Oracle I had problems to get things running. In one case only a pro version allowed to do an analysis for a remote database installation (what is the normal case for Oracle schemas ;-)).

Well, in the end I found a German article by Joachim Uhl that confirmed some of my experiences and gave some useful tips to get a productive solution. He prefers SchemaSpy, a Java-based commandline tool, and also develops a Java-based GUI application for it.

Although, "nominated" in 2006, SchemaSpy seems to be still the best OpenSource tool for schema documentation. The list of databases, that are supported, is impressive. My first tests with SchemaSpyGUI, SchemaSpy and GraphViz for Windows, the tool that generates the cool dependency graphs, are promising.


SchemaSpy Online Example
Fig. 1: SchemaSpy Example for a Dependency Graph


There's an online example for a first look [Fig. 1]. If you click on the "Relationships" tab you get the first of three possible graphical presentations. Use the checkboxes for presentation changes. There's also an "Anomalies" tab that may helps to find design issues in the schema.


Before you start SchemaSpyGUI the first time, SchemaSpy and GraphViz already have to be installed on your system. GraphViz is the only guy who not resides in Javaland, so you need a platform-dependent installation instead. I tested all this on Windows XP.

The downloads:

SchemaSpyGUI delivers a simple ZIP archive you can extract to your program files directory. SchemaSpy delivers a production-ready JAR, that you may put into the existing SchemaSpyGUI directory, too. GraphViz delivers a full-blown Windows installer. There's nothing special here. SchemaSpyGUI only needs the dot.exe in the environment path, that is done automatically by the installer.


If you start SchemaSpyGUI the first time, all fields are empty. The form is pretty simple, but can only manage one profile at the moment (use buttons "Save Parameters" and "Load Parameters" for this). The profile is saved in the "sSpyGUIini.xml", so you may create a batch hack to create a schema presentation for more than one database automatically.


SchemaSpyGUI - Required Parameters
Fig. 2: SchemaSpyGUI - Required Parameters for Database Access


The "Required Parameters" defines which database to use and where the JDBC driver and SchemaSpy can be found [Fig. 2]. For the Oracle database I used

  • DB Type: orathin (all other DB parameters as usual)
  • Path to DB driver: \com\oracle\jdbc\ojdbc14\\ojdbc14- from our Maven2 repository
  • Path to SchemaSpy: \SchemaSpyGUI\schemaSpy_3.1.1.jar (as suggested above)


Fig. 3: SchemaSpyGUI - Optional Parameters for Output and Schema Selection


I also set the "Optional" parameters on the right [Fig. 3]. The "Output directory" defines the place where you can find "index.html" and all other files after processing. I also set the "Schema to explore". It is also possible to be more fine-grained using regular expressions on tables or attributes.

Don't forget to click on "Save Parameters" in the end. If you start SchemaSpyGUI the next time you click on "Load Parameters" and everything is set - except from the database password ;-).


All parameters are set. So, we can start to create the schema presentation. For this click on "Start SchemaSpy" [Fig. 3]. The log window shows messages from SchemaSpy during the processing. When everything is done click on "Show Schema Output" to have a look at the results in your Web browser.

Bitbucket is the Git solution for professional teams who code with a purpose, not just as a hobby. Get started today, it's free.


Published at DZone with permission of Rainer Eschen. See the original article here.

Opinions expressed by DZone contributors are their own.


Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.


{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}