Quick Start with Apache Derby

Download and Install Derby

  • Download the Apache Derby database.
    Note: At the time of this post, I am using version 10.10
  • To install, simply unpack the download to your favorite directory. We’ll refer to this directory as $DERBY_HOME

Start Derby server

  • $DERBY_HOME/bin/startNetworkServer

Connect to Derby

  • Run Derby’s interactive SQL tool: $DERBY_HOME/bin/ij
  • ij>connect ‘jdbc:derby://localhost:1527/sample-db;create=true;user=APP;password=APP’;
    Note: This command will connect to the Derby server running on localhost on Derby’s default port, 1527. create=true will create a database named ‘sample-db’ if ‘sample-db’ does not already exist. We will connect to Derby using Derby’s default user, APP with password APP.

Create a sample table

  • ij>CREATE TABLE SAMPLE_TABLE (SAMPLE_ID BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL, SAMPLE_FIELD VARCHAR(255), PRIMARY KEY (SAMPLE_ID));

Insert a record

  • ij>INSERT INTO SAMPLE_TABLE VALUES(default, ‘sample value’);

Query all records

  • ij>SELECT * FROM SAMPLE_TABLE;

Next steps…

You’ve just learned some Derby and SQL basics! You can now connect to Derby, create a database, create a table, insert records, and run a query . Perhaps, it’s time to dive a bit deeper. For more information on ij and Derby, you might consider a  visit to http://db.apache.org/derby/.

Thank you!

You may also like...

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Follow

Get every new post on this blog delivered to your Inbox.

Join other followers: