Tuesday, March 23, 2010

Schema Spy, A Graphical Database Schema Metadata Browser.

Schemaspy is a java based tool that analyzes the metadata of a schema in a database and generated the visual representation of it. The output is highly user friendly. You can browse through table via child and parent table relationship.

Schema Spy uses the dot executable from graphviz to generate the graphical representation of the schema and its relationship. Graphviz is the graphics visualization software that takes descriptions of graphs in a simple text language, and make diagrams in several useful formats such as images and SVG for web pages, Postscript for inclusion in PDF or other documents; or display in an interactive graph browser.

Following is the steps to execute the SchemaSpy tool (for a sample MYSQL database.)
1. Download and install Graphviz from http://www.graphviz.org/Download..php
2. Download the Schema spay jar file, Schemaspy_x_y_z.jar from http://sourceforge.net/projects/schemaspy/files/
3. Download the corresponding JDBC Connector and have it on the same source folder where the schemaspy_x_y_z.jar resides. For example for a mysql database, I would simply download mysql-connector-java-5.1.5.jar or any other latest version of mysql connector.
4. Now from the source location of your Schemaspy_x_y_z.jar file, execute schemaspy to generate the graphical representation of the schema of your database, as shown on the following syntax

java -jar schemaSpy_x.y.z.jar -t database_type -dp mysql jdbcdatabase_connector -hq -o output_Directory -db databaseName -u username -p password
for example : java -jar schemaSpy_4.1.1.jar -t mysql -dp mysql-connector-java-5.1.5.jar -hq -o out -db bisudatabae -u bishow -p north


Friday, January 22, 2010

Converting Clob Datatype to String and ViceVersa .

If you have been using Hibernate 3.x.x or greater you can easily convert clob type to string type and vice versa, i.e String data type to Clob type.

Following piece of codes demonstrate the process of doing the conversion.


Clob textClobValue;
String textValue;
String newTextValue;
Clob newTextClobValue;
InputStream textStream;
Paragraph paragraph // my domain Class that contains a clob datatypes and used to update the database connection with hibernate connection (Hibernate version >=3.0)

textStream = textClobValue.getAsciiStream(); //return inputstream
newTextValue=textValue.replaceAll("Some text","new Text"); //Replacing some text from old text.


public static String convertStreamToString(InputStream is) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder();
String line = null;

while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
return sb.toString();



 ©mytechtoday.com 2006-2010