EDT:Tutorial: RUI With DataBase Lesson 3
|< Previous | Next >|
Lesson 4: Connect to a new Derby database
Use the Derby open source database manager to handle the data store for the application.
This tutorial uses the open source Derby database. In this chapter, you connect to a Derby database and create the table to be accessed. Alternatively, you can connect to a Cloudscape, DB2® UDB, or SQL Server database. In any case, create the table described in this lesson.
Follow these steps to set up the Derby database:
- Install Derby plugins in the Eclipse IDE
- Add Derby nature to the Service Project
- Start the Derby server
- Create an SQL database connection .
- Create a script in an SQL file to create a table within the database..
Install Derby Plugins
- Download the Derby Eclipse plugins into your Eclipse IDE as directed by the Derby site. The plugins for the Apache Derby 10.8.2.2 Release work well. There will be two plugin zip files for the release:
- derby_core_plugin - provides the Derby jar files to other plugins in Eclipse.
- derby_ui_doc_plugin - provides an Apache Derby Nature in Eclipse for easy database application development.
- Extract the plugins to the Eclipse home directory. As a result, the eclipse/plugins directory received these folders:
Add Derby Nature To Service Project
To add the Derby nature to the ServiceProject:
- Right click on ServiceProject in the project explorer
- On the dropdown menu, left click on Apache Derby > Add Apache Derby Nature
Start Derby Server
To start the Derby server, left click on selection Start Derby Network Server from the Derby menu.
You should see messages like this in the Console view:
Wed Nov 23 09:07:39 EST 2011 : Security manager installed using the Basic server security policy.
Wed Nov 23 09:07:40 EST 2011 : Apache Derby Network Server - 10.8.2.2 - (1181258) started and ready to accept connections on port 1527
Make a note of the sever port for future use.
Create Database Connection
- From the file menu, left clink on New and select the Connection > Connection Profile.
- On Connection Profile window, select Derby as profile type and enter a name and description for your server.
- Left click on Next.
- On Driver and Connection Details window, select Derby as profile type and enter a name and description for your server.
- Left click on Test Connection. Make sure you get a successful response.
- Left click on Next to see a summary of the connection information.
- Make a note of the server URL for future use and left click on Finish.
Create Payment Table
Create the Payment table to be used in the application using this create SQL statement::
CREATE TABLE PAYMENT ( PAYMENT_ID INT PRIMARY KEY NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1), CATEGORY INT, DESCRIPTION CHAR(30), AMOUNT DECIMAL(10,2), FIXED_PAYMENT SMALLINT, DUE_DATE DATE, PAYEE_NAME CHAR(30), PAYEE_ADDRESS1 CHAR(30), PAYEE_ADDRESS2 CHAR(30));
- From the file menu,left clink on New and select the SQL Development > SQL File wizard.
- On the Create SQL File window, enter SQL file attributes as shown in the image below.
- Left click on Finish
- Copy and paste this SQL statement into the SQL file editor window
- Close and save the SQL file.
- From the Project Explorer view, right click on file CreatePaymentTable.sql in the ServiceProject and select Execute SQL files from the menu. Look for results in the SQL Results view after the file runs.>.
- The PAYMENT_ID column is an identity column, which means that Derby will place a unique value into that column whenever the user creates a record. Each value is one more than the last.
- The names of Derby tables and columns are always in uppercase regardless of the case of names that are in the CREATE TABLE statement.
In this lesson, you completed the following tasks:
- Created an Derby database connection
- Created a database named sample
- Created a database table named PAYMENT
In the next lesson, you start writing application code.
|< Previous | Next >|