Menu

#3 Modify script to change the driver

v1.0 (example)
open
nobody
4
2013-12-18
2013-12-18
No

I just downloaded the application to test a db2 database, but I needed to modify many scripts (runSQL, runLoader, runBenchmark) in order to load the right drivers and execute the benchmark.

However, I found that the scripts and the documentation is oriented to postgres. It is not bad, but it could be more flexible.

I would like to propose to create a symbolic link to the postgres driver. In this way, the scripts reference to the symbolic link, and by default it uses postgres. For other users, like me, we need to replace the symbolic link to point to our own driver, in my case the db2jcc4.jar.

For example, in the run directory execute:

ln -s ../lib/postgresql-9.3-1100.jdbc4.jar jdbc-driver.jar

and then, replace the scripts with lines like this:

runSQL.sh
myCP="./jdbc-driver.jar"

runBenchmark.sh
java -cp .:./jdbc-driver.jar:../lib/log4j-1.2.17.jar:../lib/apache-log4j-extras-1.1.jar:../dist/BenchmarkSQL-4.0.jar -Dprop=$1 jTPCC

For other databases, it is not necessary to modify the script, but just remove the link and recreate. In my case

rm jdbc-driver.jar
ln -s /home/db2inst1/sqllib/java/db2jcc4.jar jdbc-driver.jar

If the symbolic link is not a good option, you could also put a env variable, and use parameter expansion.

For example, in all scripts put a variable like this
JDBC_DRIVER=${JDBC_DRIVER:-../lib/postgresql-9.3-1100.jdbc4.jar}

java -cp .:${JDBC_DRIVER}:../lib/log4j-1.2.17.jar:../lib/apache-log4j-extras-1.1.jar:../dist/BenchmarkSQL-4.0.jar -Dprop=$1 jTPCC

If the variable is not defined, the script will override this with the postgres value. Other users will defined before call the script just by doing this:
export JDBC_DRIVER=/home/db2inst1/sqllib/java/db2jcc4.jar

For more information:
https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html

Discussion


Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.