dbmsjy and Jython/JDBC Scripts

Contents

Return to main dbmstools documentation page.

Introduction

Several of the dbmstools scripts interact directly with databases, and they use Java's JDBC API to do so. These scripts (db2sql, db2xml and dbclear) need to be run using the dbmsjy wrapper script, and they also have a couple of other prerequisites (Java, and a JDBC driver).

Some background - these scripts use Jython, which is an implementation of a Python runtime that runs within a Java Virtual Machine, and it's a wonderful tool if (like me) you're wedded to Java but keep Python as a mistress.

dbmstools ships with a stripped-down version of Jython that's already tailored to run the db* scripts, although it can be used to run any of the dbmstools scripts.

Prerequisites

To use dbmsjy, you must have a Java Virtual Machine installed.

To use any of the db* scripts that connect to a database, you will need a JDBC driver for your database.

Java Virtual Machine

Many computers will already have a Java VM already installed (try typing java -version in a command prompt to check).

dbmstools is currently tested using Java 1.6, and also occasionally with 1.5 and 1.4. Later versions are usually significantly faster, so I recommend using Java 1.6. It's likely that 1.3 will still work, and it's also likely that most functions will work using the open source GCJ system (but JDBC drivers like Oracle's may not). I haven't tested it with OpenJDK.

If you need to install a Java VM, you can get one for most platforms from http://www.java.com/getjava/. Note that I haven't done much testing of dbmstools with gcj (a free Java implementation) - the main issue may be interaction between gcj and your JDBC driver.

Note that Java must be in your path (most common), or you must set the JAVA_HOME environment variable to point to it.

JDBC Driver

The JDBC driver will depend on your DBMS, and in some cases which drivers you have access to. dbmstools can use any JDBC driver of version 2 or above (of the JDBC API).

You need to copy (or link) the JDBC driver into the jdbc-drivers directory in dbmstools, where it will be found by dbmsjy.

dbmstools has been tested with the following drivers (and default driver classes):

DBMS Default Driver Class Description Sample JDBC URL
Mssql com.microsoft.jdbc.sqlserver .SQLServerDriver Microsoft's own JDBC driver (the default for Mssql) jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=test
Mssql com.inet.tds.TdsDriver A commercial JDBC driver, from iNet. jdbc:inetdae7:localhost:1433?database=test
MySQL com.mysql.jdbc.Driver Standard MySQL driver This may be called something like mysql-connector-java-3.1.12-bin.jar jdbc:mysql://localhost:3306/test
Oracle oracle.jdbc.driver.OracleDriver Standard Oracle driver This may be called ojdbc14.jar jdbc:oracle:thin:@localhost:1521:xe
Postgres org.postgresql.Driver Standard Postgres driver This may be called something like postgresql-8.0-xxx.jar, where xxx is the version number jdbc:postgresql://localhost:5432/test

Execution - The dbmsjy.py Wrapper Script

The dbmsjy.py script acts as a wrapper for any other script, to run it under Jython. It takes responsibility for:

Ensure that you've installed your JDBC driver into the jdbc-drivers directory, then use dbmsjy.py to execute the script you really want to run. Note that you don't need to include the path to the real script to be run - if omitted, dbmsjy.py looks in its own directory for the script.

On Linux or Unix:

[johnd@rama dbmstools]$ main/dbmsjy.py db2xml.py ...

It's basically the same on Windows:

C:\dbmstools> main\dbmsjy.py db2sql.py ...

If you have any problems, pass the -v option to dbmsjy.py, and check the output. If you receive a message about running out of memory, use the -m option with a value above 128, e.g.

main/dbmsjy.py -m 256 db2sql.py ...