Table of Contents

Java DB - Getting Started

About

First steps with Java DB and the ij client tool.

The semicolon (;) is the ij command terminator.

Steps

Installation

There is two installation option:

subdirectory of the JDK installation

Java DB/Derby may be installed automatically as part of the Java SE Development Kit (JDK).

Java DB has been available as part of the JDK since JDK 6.

Java DB can be found in the db subdirectory of the JDK installation.

The distribution contains scripts and libraries. The installation contains the following subdirectories:

Set the derby_home environment variable.

Download and Unzip

If Derby is not installed

For instance, for Java8

unzip db-derby-10.14.2.0-bin.zip
cd C:\db-derby-10.14.2.0-bin
λ ls -A1
bin/                         
demo/                        
docs/                        
index.html                   
javadoc/                     
KEYS                         
lib/                         
LICENSE                      
NOTICE                       
RELEASE-NOTES.html           
test/                        

Environment variable Configuration

To be able to use shortened commands to start the Derby tools:

DERBY_HOME

The DERBY_HOME Environment variable is a variable that store the location of the root Derby directory.

SET DERBY_HOME=C:\Program Files\Java\jdk1.7.0\db
SET DERBY_HOME=C:\db-derby-10.14.2.0-bin

Verification In the bin directory, you should have the ij tool

cd %DERBY_HOME%%\bin
ls -A1
dblook*                   
dblook.bat                
derby_common.bat          
ij*                       
ij.bat                    
NetworkServerControl*     
NetworkServerControl.bat  
setEmbeddedCP*            
setEmbeddedCP.bat         
setNetworkClientCP*       
setNetworkClientCP.bat    
setNetworkServerCP*       
setNetworkServerCP.bat    
startNetworkServer*       
startNetworkServer.bat    
stopNetworkServer*        
stopNetworkServer.bat     
sysinfo*                  
sysinfo.bat               

PATH

Add the DERBY_HOME/bin directory to the PATH environment variable so that you can run the Derby scripts from any directory.

Path Bin Derby Home

CLASSPATH

In most development environments, it is best to temporarily set the CLASSPATH environment variable in the command line shell.

Derby provides several scripts in the DERBY_HOME/bin directory to help you set your classpath quickly. These scripts are:

If you want to call the Derby tools directly using Java and not using the scripts, you must manually set the CLASSPATH environment variable.

Creation of the database

Call of the ij tool

%DERBY_HOME%\bin\ij
ij version 10.8
ij>

Creation of the database on the first connection with the embedded driver.

CONNECT 'jdbc:derby:firstdb;create=true';

where:

Creation of a table

CREATE TABLE FIRSTTABLE
    (ID INT PRIMARY KEY,
    NAME VARCHAR(12));

The default schema is the user app

Javadb Derby First Table

Insert

INSERT INTO FIRSTTABLE VALUES (10,'TEN'),(20,'TWENTY'),(30,'THIRTY');

Select

ij> SELECT * FROM FIRSTTABLE;
ID         |NAME
------------------------
10         |TEN
20         |TWENTY
30         |THIRTY

Running a script

run 'mypath/to/the/script.sql';

Exit

exit;

Impact on the File System

derby.log

The derby.log file is a message and error log that, under normal circumstances, contains a set of startup messages and a shutdown message.

database directory

Under the current directory you will find a directory with the name of the database. (firstdb). Within the directory are the subdirectories:

Documentation / Reference