First steps with Java DB and the ij client tool.
The semicolon (;) is the ij command terminator.
There is two installation option:
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.
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/
To be able to use shortened commands to start the Derby tools:
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
Add the DERBY_HOME/bin directory to the PATH environment variable so that you can run the Derby scripts from any directory.
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.
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:
CREATE TABLE FIRSTTABLE
(ID INT PRIMARY KEY,
NAME VARCHAR(12));
The default schema is the user app
INSERT INTO FIRSTTABLE VALUES (10,'TEN'),(20,'TWENTY'),(30,'THIRTY');
ij> SELECT * FROM FIRSTTABLE;
ID |NAME
------------------------
10 |TEN
20 |TWENTY
30 |THIRTY
run 'mypath/to/the/script.sql';
exit;
The derby.log file is a message and error log that, under normal circumstances, contains a set of startup messages and a shutdown message.
Under the current directory you will find a directory with the name of the database. (firstdb). Within the directory are the subdirectories: