> List of tutorials

Table of contents for this tutorial

Base lesson 2, step 5: Run SQL-commands against the database

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-24

This step of the tutorial
* shows how to create a 'thread' and
* reads the SQL-commands from the input-file and performs the SQL-commands against the database.

A 'thread' is a technology that allows parallel execution of different parts of applications.
One aim of this step of the tutorial is to show the executed SQL-commands and the response of the database in the text-area of the GUI.
Without a 'thread' the text would be re-displayed after the whole set of SQL-commands was processed.

With a 'thread' there are two parallel tasks:
* reading the SQL-commands out of the input-file and performing them against the database and
* periodically updating the text-area.
So a part of the SQL-commands and the response of the database can be displayed while further SQL-commands are in the queue waiting to be processed.

Preface:

The code written in this tutorial is far away from being optimized.
Emphasis of this tutorial is to develop the application in small steps where the completion of each step allows the application to be run eror-free and showing the result aimed by the step.
Therefore the code is written to be understandable in favor of being optimized
.

Credits:

I derived the guideline how to access a database within a JAVA-application from:
www.developer.com/java/data/article.php/3417381.

Prerequisites:

Adding an additional class for the 'Thread':

A thread must be run in its own class.
Therefore a new class must be created which will hold the code to read the SQL-commands from the input-file, run the commands against the database and update the text-area with the response from the database.

top.

Coding the reading of the input-file:

As the framework of the 'Thread' is implemented and coded, code for the business-application follows.
The next task - before running the SQL-commands against the database - is to read the input-file with the SQL-commands.

top.

Coding the execution of the SQL-commands:

Now it is time to execute the SQL-commands that were read from the input-file.

top.

Next Step: