-
Notifications
You must be signed in to change notification settings - Fork 20
RandomQueryGeneratorJavaDBForRQGUsers
A short Java DB crash course for RQG users
Java DB is Oracle's branded version of Apache Derby pure Java SQL database. Java DB may both run in embedded mode and server mode and both. In the rest of this document, we will use the term Derby.
- Apache Derby 10.5.3 or newer (http://db.apache.org/derby/derby_downloads.html). Download the lib distribution (either .zip or .tar.gz) and unpack it in a suitable location, it will contain a set of .jar-files.
- DBD::JDBC. This as a DBI package combined with a proxy server for JDBC enabled databases. You will need both the DBD package and the dbd_jdbc.jar file (http://search.cpan.org/~vizdom/DBD-JDBC-0.71/JDBC.pod)
- Apache log4j (http://logging.apache.org/log4j/1.2/download.html). Download either the .zip or the .tar.gz file and unpack it into a suitable location (it is the log4j jar-file we're interested in).
- Standard Java 6 or 7. I have personally tried using gij on Ubuntu and for some reason, this causes 'driver not found errors' when trying to connect to the server. Using standard (Oracle's) java allowed me to run Derby without problems.
- If you receive a message such as:
Exception in thread "main" java.lang.InternalError: One of the management beans is not compliant. <br>
removing the following packages (at least on Ubuntu) helped:
- java-gcj-compat
- java-gcj-compat-headless
- If you receive a message such as:
log4j:WARN No appenders could be found for logger (com.vizdom.dbd.jdbc.Server). log4j:WARN Please initialize the log4j system properly.
It is because you need a log4j properties file, the DBD_JDBC tarball contains a sample:
DBD-JDBC-0.71/t/hsqldb/log4j.properties.
This file needs to be in the classpath (just add it to the -classpath statement in the embedded server example below)
All logging is off in this sample, please consult the DBD-JDBC page for more information on how to alter logging.
ij is Derby command line tool. The easiest way to run Derby is to use ij and embedded Derby, like this:
java -jar /path/to/derbyrun.jar ij ij> connect 'jdbc:derby:memory:mydatabase;create=true'; ij> .... SQL statements
This will create an in-memory database which you may use.
Read the Derby docs for more details on the URL. (http://db.apache.org/derby/manuals/index.html#docs_10.5)
I prefer to run the DBD::JDBC server with the Java DB network server started. In this way, I may access the same database through DBI (using an embedded Java DB database inside the DBD::JDBC server) and though the Derby Network Client driver.
I start the server like this:
java -Ddbd.port=1234 -Djdbc.drivers=org.apache.derby.EmbeddedDriver \ -Dderby.drda.startNetworkServer=true \ -classpath /path/to/dbd_jdbc.jar:/path/to/log4j-1.2.15.jar:/path/to/derbynet.jar \ com.vizdom.dbd.jdbc.Server
A DSN for a Deby database will look like this:
dbi:JDBC:host=somehost;port=1234;url=jdbcurl
The RQG assumes that url= is the last dsn attribute. This is because ";" and "=" needs to be encoded before connect is called to avoid confusion in DBI. Complete example on the command line (gentest.pl):
--dsn2=dbi:JDBC:hostname=localhost\;port=1234\;url=jdbc:derby:memory:test\;create=true