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
Start Derby server
Connect to Derby
- Run Derby’s interactive SQL tool:
- ij>connect ‘jdbc:derby://localhost:1527/sample-db;create=true;user=APP;password=APP’;
localhoston Derby’s default port,
create=truewill 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;
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/.