Difference between revisions of "Getting Started with DTP"
(→Connecting to Apache Derby)
(→Using the Apache Derby Connection)
|Line 43:||Line 43:|
Revision as of 12:29, 17 April 2006
This page describes steps to get started with DTP 0.7 and the 0.9 streams. We assume that you have installed the appropriate version of the Eclipse platform, EMF and GEF as described on the DTP downloadpage for your specific DTP build. We also assume that you have downloaded Apache Derby version 10.x, and are generally familiar with it. We also assume that you are familiar with using Eclipse features such as preference pages, editors, views, and so on.
While DTP is not solely about databases, we have used relational databases as our primary set of examples in DTP 0.7 and 0.9. Further, we have selected Apache Derby as our sample database. Therefore, this guide will show the basic steps required for connecting to, and working with, Apache Derby using DTP.
Connecting to Apache Derby
The following are the essential steps for connecting to Apache Derby using DTP.
Defining a Driver Template
- Once Eclipse+DTP is running, open the Preferences dialog and select Connectivity-->Driver Definitions:
Since this is the first time to create a driver definition, there will be no entries under Derby Embedded. Select Derby Embedded and click on Add, launching the driver definition wizard:
Select Derby Embedded JDBC Driver... for the version of Apache Derby you have, change the name of the driver name (if you wish), and click on OK. This opens the driver details dialog:
Clear the sample derby.jar location and point to the correct one for your Apache Derby install. An embedded Apache Derby database doesn't require a user name or password, so those properties can be left blank. You might want to alter the url to point to another location for the embedded database.
Creating a Connection Profile for Apache Derby Embedded
Once you have created an Apache Derby embedded driver definition, you can then use that as the basis to create a connection profile. Open the Perspective selection dialog in Eclipse, and choose the Database Development perspective. Once open, this perspective should look like the following:
The Data Source Explorer (DSE) is found on the lefthand side. Right click on the Databases category and select New. This opens the new connection profile wizard:
Select Derby Embedded Database and click Next. After you give the connection profile a name and, optionally, a description, a dialog will open where the driver definition is to be selected:
Drop the combo box and choose the Apache Derby driver definition that you previously created, and click on Finish. The connection profile has now been created.
Connecting to Apache Derby
With the connection profile in place, you are now ready to connect to the embedded Apache Derby instance. Expand the Databases node in the DSE, select the connection profile you created, right click, and select Connect. After a few moments (the initial contents for the database instance are being created), you should be able to expand into the connection profile an examine the contents of the embedded Apache Derby database. The following shows an example expansion set:
Using the Apache Derby Connection
The are a number of ways to use a connection in DTP. Below we will discuss two of the most common for relational databases. The first is to call a stored procedure in the database. We can do this with Apache Derby by expanding into the Stored Procedures node under the SYSIBM schema. As an example, let's choose the SQLTABLES stored procedure. Right click on it, and choose Run.... This causes the routine editor to open, and a dialog for input value entry. Leave the defaults in the input value dialog, and choose OK. The stored procedure is executed, and the output is shown in the SQL Results view:
You can also create a SQL file and run it against as given database instance. First, create an Eclipse project, and then add a SQL Scrapbook Page to it (via the standard Eclipse New... wizard). When the DTP SQL Editor opens, the first thing you'll want to do is define which database connection it should target. Right click in the editor and choose Set Connection Info. The following dialog appears: