|Note: MyEclipse now come with Derby includes as an integrated test database. There is no need to do anything to configure this sandbox version, though there are associated preferences. If you want a simple database on which to test, use this embedded version of Derby (there is a Derby Database Server Tutorial, in the workbench help). Otherwise, you may install an external version and follow this guide.
The Apache Derby is a great Java-based multi-use database (along with HSQLDB
). Both of these databases can be set to run in-memory (embedded) or as a service like a more typical DBMS install. This tip will cover how to install and run Derby in-memory.
This is extremely helpful when testing an application and you need a temporary DB to run all your tests against.
Installing Apache Derby
1) Go here for the latest stable Derby release and download the BIN ZIP file.
2) After downloading it, unzip the file to some location (it will create a db-derby-<VERSION>-bin subdirectory)
Believe it or not, now we are done with the installation. Since the DB is going to run in-memory, just making "connect" calls via the embedded JDBC driver will actually create the DB for us, we don't need to do any more installing or initialization.
Connecting to Apache Derby
These instructions look long, but they are very straight forward and most of them you only need to do once...
1) In MyEclipse, switch to the "MyEclipse Database Explorer" perspective:
2) Click the "New" connection button:
3) Name the profile (e.g. "Embedded Derby Connection")
4) Click "Configure database driver"
5) Click "New..."
6) Select "Derby" (2nd one from top)
7) In the "Driver JARs" tab, click "Add JARs..."
8) Find your derby.jar file in the /lib directory under the derby directory we unzipped from the section above.
9) Use the "Driver classname" drop-down box to select the org.apache.derby.jdbc.EmbeddedDriver class:
10) Hit OK, select Derby and hit OK again (Notice that the Driver on the connection dialog should be "Derby")
11) Set the URL to jdbc:derby:derbyDB;create=true and leave everything else blank ("derbyDB" is the name of our DB, you can name it anything you want)
12) Hit Finish
Now you can select the Derby connection and hit the "Open Connection" button to connect to your Derby DB.
: Because this DB runs in memory (the way we have set it up) all state of the DB will be lost between disconnect and reconnect. If you need to persist your data to your hard drive or want to setup Derby as a normal server service, please see the Derby Documentation