Using JDBC IO with dre command-line tool

A common "gotcha" when using the JDBC API is making sure that your driver is found by the client of the JDBC API. This tutorial discusses this problem when the client is a DataRush application that uses the ReadFromJDBC or WriteToJDBC operators, and you wish to run the application using the dre command-line tool.

For more information on ReadFromJDBC and WriteToJDBC, see the reference manual (datarush_programmers_reference.pdf in the command-line SDK).

The problem

Supposing (for example) that your driver class is "com.mysql.jdbc.Driver", you may see a stack trace when you run dre, including the message java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

Where to put your driver

In order for your driver class to be found, you must put your JDBC driver jar in a place where it will be part of the classpath used to launch java.exe. With the dre command-line tool, there are 3 choices:

  1. The lib directory of your DataRush SDK
  2. The dre/lib directory of your DataRush SDK
  3. The jre/lib/ext directory of your Java 6 SDK

If you put a copy of your driver in any of these locations, your driver class should be found by ReadFromJDBC or WriteToJDBC.

But shouldn't it work if I...?

The following methods of using a JDBC driver are not supported

  • Adding to the CLASSPATH environment variable. This does not work, because the DataRush command-line tools put together a classpath for java.exe without using the CLASSPATH environment variable. This applies to all java code, not just JDBC drivers.

  • Including the jar in the -cp command-line flag. This does not work for a more suble reason specific to JDBC. The problem is JDBC's DriverManager, which looks for a driver using classes preloaded using Class.forName. Unfortunately, Class.forName is not aware of the extra classpath provided by -cp, which is used by the DataRush engine for loading your applications and custom operators.

Trackback URL for this post:

http://www.pervasivedatarush.com/trackback/135