RandomQueryGeneratorJavaDBForRQGUsers
A short JavaDB crash course for RQG users
Contents |
[edit] On JavaDB
JavaDB is Sun's branded version of Apache Derby pure Java SQL database. JavaDB may both run in embedded mode and server mode and both. In the rest of this document, I will use the term Derby.
[edit] What you need
- Apache Derby 10.5.3 or newer (http://db.apache.org/derby/releases/release-10.5.3.0.cgi). 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 dfatabase. 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). Down load either the .zip or the .tar.gz file and unpack it into a suitable location (It's the log4j jar-file we're interested in.
- standard Java6. 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 (Sun's) java allowed me to run Derby without problems.
[edit] Notes
- If you receive a message such as:
Exception in thread "main" java.lang.InternalError: One of the management beans is not compliant.
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.
[edit] Running ij
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)
[edit] Running the DBD::JDBC Server
I prefer to run the DBD::JDBC server with the JavaDB network server started. In this way, I may access the same database through DBI (using an embedded JavaDB 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
[edit] The DSN
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