| Java, Eclipse and Web programming Tutorials |
Version 0.9
Copyright © 2007 - 2010 Lars Vogel
25.01.2010
| Revision History | ||
|---|---|---|
| Revision 0.1 - 0.5 | 17.01.2008 | Lars Vogel |
| Created Article | ||
| Revision 0.6 | 05.01.2009 | Lars Vogel |
| Corrections, added ij handling of derby | ||
| Revision 0.7 | 20.01.2009 | Lars Vogel |
| Moved Derby description to own article | ||
| Revision 0.8 | 24.06.2009 | Lars Vogel |
| Upgrade to Eclipse 3.5 (Galileo) | ||
| Revision 0.9 | 25.01.2010 | Lars Vogel |
| General rework | ||
Table of Contents
The Eclipse DTP project provide tools for performing database tasks. For example the project provides an editor for SQL statements or a database browser.
In this article Apache Derby is used as the example database but Eclipse DTP contains connectors for lots of other databases, e.g. MySQL, PostgreSQL, HSQLDB.
Derby is an open-source, freely available, pure Java database. See Apache Derby Tutorial to learn more about Apache Derby.
Install the Data Tools Platform via the Eclipse update manager . Install "Data Tools Platform Enablement Extender SDK"
Please see Using the Eclipse Update Manager for information on the Eclipse update manager.

Download the latest Derby version from the Apache website http://db.apache.org/derby/ . Choose the binary distribution.
We will create a project to contain the SQL files.
If you have problems with the following please see Eclipse Java IDE Tutorial .
Create a new General Project "de.vogella.dtp.example" via File-> New -> Other -> General -> Project.
Add a folder "lib" to your project. Copy the file derby.jar from your Derby download into this folder.
The result should look like the following.

The following will create a connection for an embedded Derby.
Define the driver for the derby access. Go to Window-> Preferences and select "Data Management" -> Connectivity -> Driver Definition. Press Add. Select Derby and the version you want to use. If your Derby version is not listed selected the highest number displayed.

Select then the tab jar press "Add" and select the derby.jar from your project folder "lib".

Switch to the perspective "Database Development". Please see Eclipse Perspective to see how to switch a perspective.

Select "Database Connections", right mouse click and select new.

Select Derby.

Maintain a Database location where the new database should be stored on your file system. The flag "Create database (if required)" should be selected. Maintain user and password and press finish.

Congratulation! You have created a new database.
Now your folder Database should have an additional entry. Right it and select connect (if you not connected).

Open then tree to see the content of your new database.

Congratulation. You have connected yourself to the new database.
Switch back to the Java perspective. Create a folder "scripts". Right click on it, select New -> Other and SQL Development and SQL File.

Maintain the folder "scripts" as a target, name the file "myscript.sql" and maintain the connection you have created earlier.

Maintain a SQL statement, e.g. the creation of a Database schema, right click and select "Execute all". After running the script you see the result in the "SQL Results" view.


Switch back to "Database development" perspective, right click on your database and select refresh to see your new schema. You could continue now writing SQL statements to create your database, e.g. creating a table via SQL.
Create a table with the following coding.
CREATE TABLE MYKILLERAPP.MyTabelle ( ID INTEGER NOT NULL, MyKey INTEGER NOT NULL, Content VARCHAR(20) NOT NULL, PRIMARY KEY (ID) );
Put in some data via SQL
insert into MYKILLERAPP.MyTabelle values (1,1,'Hallo');
Refresh your database and select your new table, right click on your table and select Data->Edit. Now you can edit the data.


Also note that Eclipse Data Tools Platform allows you to upload / download the data and also to see a sample of the content.

Thank you for practicing with this tutorial.
Please note that I maintain this website in my private time. If you like the information I'm providing please help me by donating.For questions and discussion around this article please use the www.vogella.de Google Group. Also if you note an error in this article please post the error and if possible the correction to the Group.
I believe the following is a very good guideline for asking questions in general and also for the Google group How To Ask Questions The Smart Way.