> List of tutorials

Base lesson 2: A DataBase-Loader with a GUI (Graphic User Interface)

For this document and all references (links) please obey the hints and regulations concerning copyright, disclaimer and trademarks.

Last revision of this document:
2006-02-10

This lesson is a tutorial to develop an GUI-application with the following purpose:

  1. Read SQL-commands from a text-file which can be chosen via the file-selection-mechanism of Java.

  2. Read the paramater for the connection to the database from a XML-file with a name defined in the application (DB.XML).

  3. Make a connection to the database and perform the SQL-commands read from the text-file;
    list all commands and the response-messages from the database in a scrollable text-area.

  4. Allow a printout of all SQL-commands and the response-messages.

The final GUI of the application will look like this:

Credits:

Individual credits for each step are listed in the individual document for each step.

Prerequisites:

Structures:

An overview of the classes that make up the application can be found in the document JA_Base02_A - Class-Overview.

Reference to the individual steps:

Step

Task

JS_Base02b, Step 1 - GUI-Design

Design the elements of the Graphic User Interface (GUI) of the application.
Get familiar with the elements (fields, text-area, button) and the the concept of the Gridbag-Layout.

JS_Base02c, Step2 - Adding an action: selecting the file with the SQL-commands

Handle when a button is clicked (an action event) and code a method, that allows the selection of a file (the one containing the SQL-commands that should be executed against the database in a further step).
Additionally, the directory which holds the input-file and the XML-file with the database-parameters is created.

JS_Base02d, Step 3 - Read parameters for the connection to the database

After clicking the button 'Start SQL execution', the parameters for the connection to the database are read from the file in XML-format.

JS_Base02e, Step 4 - Connect to the database

After the connection-parameters are verified, the trial to connect to the database is started.

JS_Base02f, Step 5 - Run SQL-commands against the database

If the connection to the database was successful, the SQL-commands are performed against the database.
This is done in a 'thread'. So the text-area can be periodically updated and the performed SQL-commands and their results can be watched.

JS_Base02g, Step 6 - Print out the report

Code to allow a printout of the report is implemented..

JS_Base02h, Step 7 - Pack the project into a JAR-file and run it

Pack the whole project in a JAR (Java-ARchive) and run it.

JS_Base02 - Code

The complete Code of all classes.
For an overview or easy 'cut and paste' ;-) .

Related Documents: