> List of tutorials

Table of contents for this tutorial

Base lesson 2, step 4: Connect to 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-22

This step of the tutorial
* adds the JAR-file with the package for access to SQL-databases and
* connects to a database specified by the parameters read from a XML-file (see previous step).

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:

Preparation:

Methods for accessing databases within JAVA-applications are contained in an (external) Java-ARchive depending on the database-system used.
For this example, MySQL is used.
The download of the JAR-file with the MySQL-specific packages is described under JS_DB01 – Set up the MYSQL database for access by JAVA-applications.

For the following descriptions in this tutorial, it is assumed, that the JAR-file has the name 'mysql-connector-java-3.1.12-bin.jar' and is stored in directory '/usr/java/j2sdk1.4.2_08/lib/extern' .

Code to connect to the database:

In the following explanations all new code is written in bold letters.
Code generated by the template or entered in previous steps (old code) is in italics.
Larger blocks of old code may be skipped.

top.

Next Step: