In this blog post, we’ll body a database diagram account the metadata of the sample MySQL database sakila.
The schema used for MS SQL Server database | Download Scientific Diagram – Database Schema Diagram | Database Schema Diagram
PDF) UMLtoGraphDB: Mapping Conceptual Schemas to Graph Databases – Database Schema Diagram | Database Schema Diagram
The nesting operator on a database schema | Download Scientific Diagram – Database Schema Diagram | Database Schema Diagram
For our sample to assignment we charge to add the JDiagram.jar amalgamation to the activity and a JDBC disciplinarian for MySQL. We download the JDBC disciplinarian from https://dev.mysql.com/downloads/connector/j/ and we add mysql-connector-java-5.1.40.jar to the libs binder of our activity area we accept placed JDiagram.jar.
We actualize several abettor classes that will handle the affiliation to the database and account of the database metadata in a architecture which we can use to body the DB diagram.
1. We accept created two classes for abutting to the sakila MySql database and account the metadata. For the tables. In accepted we are absorbed in the names of the tables, the columns in them with cavalcade name, cavalcade abstracts blazon and cavalcade abstracts size. We additionally appetite the relationships in the database, with the primary and adopted keys. The classes that accommodate us with this advice are DBConnection, which binds to the database and DBMetaData, which reads the database with the advice of the DatabaseMetaData and ResultSet classes of the Java platform.
2. For the purpose of our activity we accept created two added classes. The aboriginal one represents a cavalcade in the database – DBColumn. It has aloof a few fields:
The added chic describes a affiliation in the database. It is appropriately simple:
3. We accept authentic an ArrayList tables capricious for the table names. We alarm the corresponding adjustment of the DBMetaData chic that reads the table names and populates the tables list.
The nesting operator on a database schema | Database Schema Diagram
We will use an instance of the Diagram class, a DiagramView control, a JScrollPane and a zoom control. What we appetite to actualization is a diagram area that is scrollable both angular and angular and a zoom ascendancy abutting to it.
We actualize the diagram and accomplish abiding it will resize itself back needed:
The diagram needs a diagramView to cede itself onto. We actualize one and add it to a JScrollPane. The annal area provides the all-important scrollbars if the flowchart gets too big.
The Java Diagram library provides a scattering of abetting controls and in our sample we’ll use the Zoom control:
We use the setView() adjustment to accessory the zoom ascendancy with the diagramView. The BorderLayout algorithm helps us adjust the controls. First, we administer it on the JFrame ContentPane and again we adjust the zoom ascendancy to the right. Finally, we add the JScrollPane to the center, which lets it use all the accessible amplitude larboard by the zoomer:
We aboriginal apprehend the abstracts for the DB columns and again for anniversary table in the database we actualize a diagram TableNode.
We use the Factory chic of the diagram library:
The createTableNode() adjustment that we use takes as arguments the area of the table node, its amplitude and acme and the calculation of rows and columns. We use HTML formatting to accomplish the explanation of the table bold. For the explanation and for the id of the tableNode we use the name of the table.
Since we charge to use HTML administration on argument in the diagram nodes we charge specify:
Let’s add some added customization on the table nodes:
The explanation is accumbent in the centermost and we access hardly the absence explanation height. Again we acquiesce users to resize table columns with the abrasion and we change the table actualization from rectangle to a rectangle with angled edges. Finally, we blush the table nodes with a ablaze dejected brush.
Note that already Factory creates a bulge it gets added to the DiagramNodes accumulating of the ascendancy automatically.
Now let’s abide the table with data:
Here, we aeon through all DBColumn altar that we accept created appliance the database metadata. In anniversary row in the table node, we address the name of the database field, the abstracts type, and the abstracts size. Note that we alpha with the additional cavalcade (index 1) because the aboriginal one is aloof for an angel of the primary or adopted key, if applicable. So far we accept aggregate advice alone for the primary key.
Since we appetite the angel to absorb the aboriginal cavalcade we charge accomplish some adjustments to the TableNode and its size:
First, we use resizeToFitText to accomplish the table auto account the admeasurement it needs based on the argument it holds. This, unfortunately, would not accommodate amplitude for the image, so we charge actual it manually. We resize the aboriginal cavalcade with 7 pixels to acquiesce the angel to fit and we access the admeasurement of the table as well. Again we alarm resizeToFitImage() to let the TableNode amend its new size.
With that, we accomplishment the aboriginal allotment of our tutorial. Allotment II will airing you through the accomplish to actualize the relationships amid the nodes and adjust the database diagram appliance the automated blueprint algorithms provided with the Java Diagram library. Actuality is our diagram so far:
You can download the complete sample from this link. The sample contains the sakila MySQL database with a PDF book with instructions how to install it if you haven’t already. You will charge to accept an installed and active MySQL server. Remember to change the login abstracts in the DBConnection.java book to bout your login credentials.
About Diagramming for Java Swing: MindFusion.Diagramming for Java Swing provides your Java appliance with all all-important functionality to actualize and adapt a diagram. The library is actual accessible to accommodate and program. There are abundant account methods, affluent accident set, added than 100 predefined shapes. The apparatus supports a array of means to cede or consign the diagram, avant-garde bulge types like TreeView nodes, hierarchical nodes, tables, alembic nodes and abounding more. There are 15 automated layouts, assorted ascribe / achievement options and absolutely customizable appearance. A abundant account with JDiagram’s appearance is uploaded here. You can analysis the online audience to see some of the functionality implemented.
Diagramming for Java Swing is ability free, there are no administration fees. Licenses depend on the calculation of developers appliance the apparatus – analysis actuality the prices.
4 Things Your Boss Needs To Know About Database Schema Diagram | Database Schema Diagram – Database Schema Diagram
| Delightful to be able to my personal blog, with this period I’m going to demonstrate regarding keyword. And after this, this can be the first image: