Wednesday, October 30, 2013

Setup Derby from scratch

The very first step after Derby is install is to create a database. In order to create a database, I must have a command prompt ready. And then decide where am I going to put my database. Assume I'll create the database in this path /home/derby/ (if derby folder doesn't exists, created one), make sure the current directory is showing /home/derby when pwd command is issued. After this, I am going to launch Derby ij tool to create the database. Try either one of the following command to launch that tool:

  1. java -jar $DERBY_HOME/lib/derbyrun.jar ij
  2. $DERBY_HOME/bin/ij

This is very important, this tool must be launch where the database is going to create. If the database create under /home/the_database directory, make sure the current directory is locate at the_database, no elsewhere. Otherwise an error message say Unable to establish connection will shown.

Now issue this command to create a database > connect 'jdbc:derby:thedb;create=true', a new folder named thedb will be created under the /home/derby directory. Usually a database will come with user authentication to ensure the data are secure. Unfortunately Derby set this configuration to false by default. To enabled user authentication, make sure derby.properties is exists in Derby installation path. If not, create it. The content should look like below. Replace username with your prefer user ID, and password with your desire password.

derby.connection.requireAuthentication=true
derby.user.username=password

To connect the database, use this command > connect 'jdbc:derby:DB_name;user=username;password=password'; Alternately, it can also be connect in this way > connect 'jdbc:derby:DB_name' user='username' password='password'; Since I am setting up the Derby for R&D on my local PC, and I have no intention to do serious work, thus I am keeping the authentication as simple as possible.

No comments: