To set up some kind of database running on your development environment, we use Apache Derby database. Apache Derby is a light weight in memory database, which is easy to setup and takes less resources, and is also perfect for testing out new concepts and trying out things that we are doing right now.
To download Apache Derby, hit over the Apache Derby website at http://db.apache.org/derby/derby_downloads.html, and download the latest release. Once the downloaded ZIP file is extracted, we will have some important folder named bin
and lib
folder as shown:
The lib
folder contains the jar that needs to be included in our program when we connect to the Derby database. The bin
contains programs like startNetworkServer.bat
and stopNetworkServer.bat
for database as follows:
After downloading and extracting the JAR file, the next step is to set environment variable. Derby recommends a couple of environment variables that need to be set.
Now, open a command prompt, and hit over to location where we have Apache Derby as follows:
Here in the preceding screenshot, we have changed the directory to the bin
directory in Apache Derby, which contains batch files and script files. For Windows OS, we need these batch files while running.
Apache Derby operates in two modes:
First, we need to start derby as Network Server mode which is similar to all the databases on one machine, and the other machine on the network that can connect to it. Embedded mode is something specific to derby.
To start derby Network Server mode, we need to run startNetworkServer.bat
as follows:
In the preceding screenshot, we can see that Apache Derby Network-Server started and ready to accept connection on port 1527
, which we can test by using a client to connect to the server. Derby actually comes with a client called ij.bat
, which can be used to connect to the server to execute queries.
So, we need to have a second command line prompt, which hits same bin
directory, and run ij.bat
to client, and executes the query to connect to the server connect jdbc:derby://localhost:1527/db;create=true';
as follows:
We can create a table using create query for table employee (as shown in the following screenshot with two column as ID
and NAME
), and insert values using insert query, and also print data to console using select query, as follows:
3.143.239.231