Am coding my final semester project. Initially I decided to do my project using MySQL as back-end but when I started out I found it bulky (having to run a server on a single PC to use it) and not at all easy, I didn’t even know where the documentation was…the package listing for it in Synaptic Package manager was confusing. So I decided to ditch MySQL in favour of Java DB/Apache Derby and I am lovin’ it! 🙂
This tutorial will teach you how to create a simple payroll program in Java using Apache’s Derby as the back-end in simple embedded mode. Even though this tutorial will be as descriptive as possible, I assume that you have some basic knowledge of DBMS concepts and Java. Also this tutorial assumes you have a Linux OS running (preferably Ubuntu 8.10).
This is a 3 part series, overview of which is as follows…
1. Installing Derby and setting up environment variables
2. Explanation of what the payroll program is going to do (Coding in Netbeans 6.1)
3. Running the code
Part 1 : Installing Derby and setting up environment variables
To install Java DB, fire up your package manager and get the following packages…
1. sun-javadb-common > essential package
2. sun-java6-javadb > essential package
3. sun-javadb-demo > cause it will have useful demo programs that you can use later for further practise
4. sun-javadb-doc > cause it explains everything you need to know about Derby (keep it handy!)
5. sun-javadb-core > essential package
Once you have installed these packages, check up location of the javadb documentation, i.e., by right clicking on the sun-javadb-doc package and checking up the installed files, by default on Ubuntu the location is /usr/share/doc/javadb/
Then right click on sun-java6-javadb and check the installed location of javadb under “installed files” tab, by default it should be /usr/lib/jvm/java-6-sun-1.6.0.10/db . As you can see in the previously mentioned path, the Java SDK I have installed is Java 6, you may different one, so take note of that.
Now append the path to your .bash_profile file and so my .bash_profile will look like this…
[email protected]:~$ cat .bash_profile
# .bash_profile
# Initialize keychain if needed
if [ -r $HOME/.ssh/identity -o -r $HOME/.ssh/id_dsa -o -r $HOME/.ssh/id_rsa ]; then
if [ ! -d $HOME/.keychain ]; then
keychain
fi
fi
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=PATH:/usr/local/sbin/:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/lib/jvm/java-6-sun-1.6.0.10/db/bin
export PATH
unset USERNAME
Next, Append the path in the code below to your .bashrc file…
export DERBY_HOME=/usr/lib/jvm/java-6-sun-1.6.0.10/db/
export PATH=”$DERBY_HOME/bin:$PATH”
export CLASSPATH=”${DERBY_HOME}/lib/derby.jar:${DERBY_HOME}/lib/derbytools.jar:${CLASSPATH}”
That’s it! Open up console and test that the environment variables are correctly set by entering…
echo $DERBY_HOME
echo $CLASSPATH
So the output should be something like…
[email protected]:~$ echo $DERBY_HOME
/usr/lib/jvm/java-6-sun-1.6.0.10/db/
[email protected]:~$ echo $CLASSPATH
/usr/lib/jvm/java-6-sun-1.6.0.10/db//lib/derby.jar:/usr/lib/jvm/java-6-sun-1.6.0.10/db//lib/derbytools.jar:
Also check by entering ij in the console, you should get the derby db console like this…
[email protected]:~$ ij
ij version 10.4
ij>
You can exit the console by keying in exit;
Additionally you can get more info by entering in console: sysinfo , the output should be as follows…
[email protected]:~$ sysinfo
—————— Java Information ——————
Java Version: 1.6.0_0
Java Vendor: Sun Microsystems Inc.
Java home: /usr/lib/jvm/java-6-openjdk/jre
Java classpath: /usr/lib/jvm/java-6-sun-1.6.0.10/db//lib/derby.jar:/usr/lib/jvm/java-6-sun-1.6.0.10/db//lib/derbynet.jar:/usr/lib/jvm/java-6-sun-1.6.0.10/db//lib/derbytools.jar:/usr/lib/jvm/java-6-sun-1.6.0.10/db//lib/derbyclient.jar:/usr/lib/jvm/java-6-sun-1.6.0.10/db//lib/derby.jar:/usr/lib/jvm/java-6-sun-1.6.0.10/db//lib/derbytools.jar:
OS name: Linux
OS architecture: i386
OS version: 2.6.27-9-generic
Java user name: sindhu
Java user home: /home/sindhu
Java user dir: /home/sindhu
java.specification.name: Java Platform API Specification
java.specification.version: 1.6
——— Derby Information ——–
JRE – JDBC: Java SE 6 – JDBC 4.0
[/usr/lib/jvm/java-6-sun-1.6.0.10/db/lib/derby.jar] 10.4.1.3 – (648739)
[/usr/lib/jvm/java-6-sun-1.6.0.10/db/lib/derbytools.jar] 10.4.1.3 – (648739)
[/usr/lib/jvm/java-6-sun-1.6.0.10/db/lib/derbynet.jar] 10.4.1.3 – (648739)
[/usr/lib/jvm/java-6-sun-1.6.0.10/db/lib/derbyclient.jar] 10.4.1.3 – (648739)
——————————————————
—————– Locale Information —————–
Current Locale : [English/India [en_IN]]
Found support for locale: [cs]
version: 10.4.1.3 – (648739)
Found support for locale: [de_DE]
version: 10.4.1.3 – (648739)
Found support for locale: [es]
version: 10.4.1.3 – (648739)
Found support for locale: [fr]
version: 10.4.1.3 – (648739)
Found support for locale: [hu]
version: 10.4.1.3 – (648739)
Found support for locale: [it]
version: 10.4.1.3 – (648739)
Found support for locale: [ja_JP]
version: 10.4.1.3 – (648739)
Found support for locale: [ko_KR]
version: 10.4.1.3 – (648739)
Found support for locale: [pl]
version: 10.4.1.3 – (648739)
Found support for locale: [pt_BR]
version: 10.4.1.3 – (648739)
Found support for locale: [ru]
version: 10.4.1.3 – (648739)
Found support for locale: [zh_CN]
version: 10.4.1.3 – (648739)
Found support for locale: [zh_TW]
version: 10.4.1.3 – (648739)
——————————————————
and you are done with installation of Derby! More to follow in Part 2.
P.S: There are more awesome tutorials on netbeans.org, check it out! 🙂
Thank you for good instruction.
For beginners :
export CLASSPATH=”${DERBY_HOME}/lib/derby.jar:${DERBY_HOME}/lib/derbytools.jar:${CLASSPATH}”
is to change in :
export CLASSPATH=${DERBY_HOME}/lib/derby.jar:${DERBY_HOME}/lib/derbytools.jar:${CLASSPATH}
Thanx, this helped me so far as to installing Java DB, now about the payroll, sounds interesting and would like to try it.
Thanks for a great Part 1, hope to read Part 2 🙂
I can follow it all so far.