Support free tutorials:











vogella training Training Books



Eclipse DTP Tutorial - Database Tools - Tutorial

Lars Vogel

Version 1.0

27.07.2010

Revision History
Revision 0.1 - 0.5 17.01.2008 Lars
Vogel
Created
Revision 0.6 - 0.7 05.01.2009 Lars
Vogel
bug fixes and enhancements
Revision 0.8 - 0.9 24.06.2009 - 25.01.2010 Lars
Vogel
Upgrade to Eclipse 3.5 (Galileo)
Revision 1.0 Lars
Vogel
Update to Eclipse 3.6 (Helios)

Eclipse Data tools Platform

The Eclipse Data Tools Platform (DTP) provides tools to simplify the handling of databases. This article demonstrates the usage of the Eclipse DTP.

This article is based on Eclipse Helios (Eclipse 3.6).


Table of Contents

1. Introduction
1.1. Eclipse Data Tools Platform
1.2. Derby - Java DB
1.3. Using Eclipse
2. Installation
2.1. Installation of DTP
2.2. Download Apache Derby
3. Project
4. Configuration
5. Working with Databases
5.1. Create a new Databases Connection
5.2. Create a new Databases Connection
6. Using SQL Statements
7. Maintaining data in a table
8. Support free vogella tutorials
8.1. Thank you
8.2. Questions and Discussion
9. Links and Literature
9.1. vogella Resources

1. Introduction

1.1. Eclipse Data Tools Platform

The Eclipse DTP project provide tools for performing database tasks. For example the project provides an editor for SQL statements or a database browser.

1.2. Derby - Java DB

In this article Apache Derby is used as the example database. Derby is an open-source, freely available, pure Java database. See Apache Derby Tutorial to learn more about Apache Derby. Eclipse DTP contains connectors for lots of other databases, e.g. MySQL, PostgreSQL, HSQLDB.

1.3. Using Eclipse

The following assumes that you already have knowledge in using the Eclipse IDE. See the Eclipse Java IDE Tutorial in case you lacking this knowledge.

2. Installation

2.1. Installation of DTP

Install the Data Tools Platform via the Eclipse update manager. Install "Data Tools Platform Enablement Extender SDK"

2.2. Download Apache Derby

Download the latest Derby version from the Apache website http://db.apache.org/derby/. Choose the binary distribution.

3. Project

Create a new General Project "de.vogella.dtp.example" via File-> New -> Other -> General -> Project. This project will store the SQL files.

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.

4. Configuration

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".

5. Working with Databases

5.1. Create a new Databases Connection

Switch to the perspective "Database Development" and 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.

5.2. Create a new Databases Connection

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.

Tip

Sometimes you have to disconnect and connect again to see the changes you did. For example if you create a new database schema.

6. Using SQL Statements

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.

7. Maintaining data in a table

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.

8. Support free vogella tutorials

Maintaining high quality free online tutorials is a lot of work. Please support free tutorials by donating or by reporting typos and factual errors.

8.1. Thank you

Please consider a contribution if this article helped you.

Flattr this

8.2. Questions and Discussion

If you find errors in this tutorial, please notify me (see the top of the page). Please note that due to the high volume of feedback I receive, I cannot answer questions to your implementation. Ensure you have read the vogella FAQ as I don't respond to questions already answered there.

9. Links and Literature

9.1. vogella Resources

vogella Training Android and Eclipse Training from the vogella team

Android Tutorial Introduction to Android Programming

GWT Tutorial Program in Java, compile to JavaScript and HTML

Eclipse RCP Tutorial Create native applications in Java

JUnit Tutorial Test your application

Git Tutorial Put all your files in a distributed version control system