DbComparison
Introduction
Welcome to DbComparison, which is a small Java utility that can compare
the layout of 2 databases. It is run from the command line,
and it can show the comparison results on screen or write them to a
file in various formats.
Features
DbComparison has the following features :
- it uses JDBC to connect to
the databases (currently only MySql)
- it currently only compares
the tabel layouts, comparison of other
things such as views is planned
- it can export the comparison
results in the following formats :
- to standard out
- to a text file
- to an HTML page
- to an XML file
- it runs as a command line
tool
- the connection parameters
can be read from a configuration file
Documentation
Installation
DbComparison can be downloaded
from here.
A
Java JRE version 1.4 is needed in
order to run this program. Either the
environment variable JAVA_HOME
has to be set, or the java executable has to be in the path.
In order to install DbComparison, you have to download the binary
distribution from here. Unzip or untar this file, which will
create a dbcomparison directory. In this directory, open the
file
dbcomparison.bat using a text editor. Here's how this file looks like :
@ECHO OFF
set JDBC_DRIVERS=
IF "%JAVA_HOME%"=="" SET LOCAL_JAVA=java
IF NOT "%JAVA_HOME%"=="" SET LOCAL_JAVA=%JAVA_HOME%\bin\java
set CP=lib\dbcomparison.jar;lib\commons-cli-1.0.jar;lib\junit.jar;%JDBC_DRIVERS%
"%LOCAL_JAVA%" -cp %CP% net.sourceforge.dbcomparison.Main %
This
file needs to be edited to add
the JDBC drivers for you database. Note that currently only MySql is
supported. To add the driver,
change the following line :
set JDBC_DRIVERS=
into :
set JDBC_DRIVERS=C:\libraries\mysql-connector-java-3.1.8\mysql-connector-java-3.1.8-bin.jar
This
assumes that the JDBC driver
was installed in the directory C:\libraries\mysql-connector-java-3.1.8.
This will be different on your system.
Running
DbComparison is run from the command line. The following options are
supported :
usage: DbComparison [options]
-c,--connection1 Connection string for first DB
-d,--connection2 Connection string for second DB
-f,--file File to export to
-h,--help Display this help
-l,--login1 Login for first DB
-m,--login2 Login for second DB
-p,--passwd1 Password for first DB
-q,--passwd2 Password for second DB
-t,--type Type of export (stdout, text, html, xml)
-u,--useconfigfile Name of config file
The idea is that you use the -c, -l and -p parameters to give the
connection details for the first database, and -d, -m and -q for the
second database. Additionally you can specify the output format using
-t, where stdout is the default. The file to be saved to is
specified with -f. Note that existing files are overwritten. All of
these parameters have equivalent long versions.
The -u parameter allows you to use a configuration file. If this
parameter is used, then the configuration file will be read first, after
which any of the other parameters are applied. Here's an example of the
configuration file :
t=html
f=diffs
c=jdbc:mysql://localhost/test1
d=jdbc:mysql://localhost/test2
l=tryout
m=tryout
p=test
passwd2=test
The parameters are specified as key/value pairs, with and equal sign
between them. The key can be the long or short version
of the parameter name.
An example command line invocation is as follows :
dbcomparison.bat -u example_config.txt
This will use the example_config.txt file as configuration file. The
equivalent using the command line arguments, is as follows :
dbcomparison.bat -t html -f diffs -c "jdbc:mysql://localhost/test1" -d "jdbc:mysql://localhost/test2"
-l tryout -m tryout -p test -q test
This should all be typed in on one line.
Output
formats
The stdout format is as follows :
--- table differences ---
MISSING-MISSING-0-0 -> contract-id-4-10
MISSING-MISSING-0-0 -> contract-name-12-45
customer-name-12-45 -> customer-name-12-50
This is the same as the text output, which will be saved to a file.
The
HTML
and
XML
output can be seen by clicking on their links.