Apache Derby
Apache Derby, the pure-Java database: run the ij tool, connect with embedded, in-memory and network URLs, and run SQL.
2 min readUpdated
Apache Derby is a relational database written entirely in Java. It runs embedded in the application’s JVM or as a network server, and was shipped with JDK 6 to 8 as Java DB and with GlassFish as JavaDB. Its ij tool is a JDBC command line for running SQL scripts and interactive queries.
Note: the Derby developers retired the project on 2025-10-10. There will be no further releases or bug fixes; 10.17.1.0 is the last release. Existing applications keep working, but choose another embedded database (such as H2 or HSQLDB) for new projects.
Start ij
With a Derby distribution unpacked and DERBY_HOME pointing at it, start ij from the bundled JAR:
java -jar $DERBY_HOME/lib/derbyrun.jar ijOn JDK 8, the bundled Java DB has the same JAR under the JDK’s db/lib directory, for example $JAVA_HOME/db/lib/derbyrun.jar. JDK 9 and later no longer include it.
If $DERBY_HOME/bin is on your PATH, the ij script sets up the class path and starts the tool:
ijYou can also start the class directly. This only works when the Derby JARs (derbytools.jar and the database JARs) are on the CLASSPATH; otherwise Java reports NoClassDefFoundError. The setEmbeddedCP and setNetworkClientCP scripts in $DERBY_HOME/bin set it for you:
java org.apache.derby.tools.ijConnect to a database
Every ij command ends with a semicolon. The connection URL decides how Derby is used:
ij> connect 'jdbc:derby://localhost:1527/sample;user=app;password=app';ij> connect 'jdbc:derby:retailpos';ij> connect 'jdbc:derby:memory:retailpos';ij> connect 'jdbc:derby:/path/to/workspace/retailpos/retailpos';jdbc:derby://localhost:1527/sampleconnects to a Derby network server on its default port 1527, with user and password in the URL. GlassFish’s JavaDB and the NetBeanssampledatabase work this way.jdbc:derby:retailposopens an embedded database in the directoryretailpos, relative to the Derby system home (by default the current directory).jdbc:derby:memory:retailposuses an in-memory database, which disappears when the JVM exits.jdbc:derby:/path/to/...opens an embedded database at an absolute path.
Add ;create=true to an embedded or in-memory URL to create the database if it does not exist, for example connect 'jdbc:derby:memory:retailpos;create=true';.
An embedded database can be opened by only one JVM at a time. If an application server already has it open, connect through its network server instead.
To start a network server of your own from the distribution:
java -jar $DERBY_HOME/lib/derbyrun.jar server startRun SQL
After connecting, type SQL statements and ij commands at the prompt. show tables lists the tables of the database:
ij> show tables;ij> select * from customer;ij> select * from product;Leave ij with:
ij> exit;