> List of tutorials for developing a Fat-Client in Java


Create the database-table 'Project' and establish the connection - Fat-Client-Development

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

  • The owner of this web-site (www.javascout.biz) is not responsible for the content of web-sites linked within this document or linked within other documents of www.javascout.biz.

  • If this document or other documents of this web-site (www.javascout.biz) infringes your rights or you think that rights of others (third parties) are infringed, please inform the author.
    An e-mail can be sent by clicking onto the 'hungry mailbox' in the upper right corner.

Last revision of this document:
2006-09-19

This step is a little bit away from pure Java-development.
Nevertheless it is neccessary to perform this 'infrastrutural' job to
* create a database,
* create a database-table (or all of them if the database-design is finished),
* assigning at least one user to the database, specify a password and granting access rights
.

Furthermore, this step introduces a file containing a XML-structure with the parameters for connecting to the established database and the methods to read the file with the XML-structure.
This document also touches the base-class that manages connections to a database and discusses the advantages of the 'ConnectionManager' class.

Shortcut:

This document covers the following steps:
Create database (js_tutorial) and grant access rights,
Log on to the just created database and create the database-table 'Project',
Alternative ways to create the database-table,

Define the XML-structure with the parameters for database-access,

Construct the ConnectionManager and verify if the connection was successful
,

Preface:

The guidance mainly assumes that a MySQL database is used – the referenced document (Set up the MySQL database for access by JAVA-applications) shows the procedure for the MySQL-database.
Database-systems from other vendors will need other procedures to create a database and database-tables – for sure !

All of the code used to connect to a database is already covered with the base-classes.
This document shows
* the layout of the XML-structure with the parameters for database-connection,
* what methods of the base-classes have to be called to establish a connection to the database and
* how the verification
.

Credits:

Too numerous to mention; the idea is available in dozens of versions – I refined a lot of ideas into my system.

Prerequisites:

Create database and grant access rights:

The parameters shown in the examples are highly dependant from the individual settings of the database-system.
As it might be very rare, that your system has exactly the same setting as mine (were I took the examples from), please be extreme careful when you adapt the commands shown in this tutorial.

This chapter is a condensed version of the guideline in Set up the MySQL database for access by JAVA-applications.
If you skipped the tutorial Base lesson 2: DataBase-Loader with a GUI, I recommend that you browse through the documents Base lseeon 2, step3: Read parameters for the connection to the database, Base lesson 2, step 4: Connect to the database and Base lesson 2, step 5: Run SQL-commands against the database to get an idea how data is stored and retrieved from a database.

If you are using the standard installation of the MySQL database-system:
for security reasons, the creation of a database and the setting of access-rights can only be done on the machine where the database-system is running

top.

Log on to the just created database and create the database-table 'Project'

For security reasons, MySQL does not allow the administrator ('root') to work with databases.
Therefore, queries and administration work (defining database-tables) must be done with a user that has grants to manipulate databases.
The GRANTs were given to the user 'mysql' in the previous step.

The parameters shown in the examples are highly dependant from the individual settings of the database-system.
As it might be very rare, that your system has exactly the same setting as mine (were I took the examples from), please be extreme careful when you adapt the commands shown in this tutorial.

top.

Alternative ways to create the database-table

Keying in each SQL-command is pretty boring particularly if the table-definition becomes a little bit more voluminous.
So there are two alternative methods to create a database-table.
Both of them use a text-file with the SQL-commands.

The folder and the name of the file can be chosen freely; I decided for folder 'DB_SCRIPTS' with file 'Create_Tables.txt' under the Eclipse-project JS_FC01

top.

Define the XML-structure with the parameters for database-access:

For some theory about the the structure of the XML-file please refer to Structure of the XML-file with the parameters for database and JAS-connection.

The parameters shown in this examples are highly dependant from the individual settings of the database-system.
As it might be very rare, that your system has exactly the same setting as mine (were I took the examples from), please be extreme careful when you adapt the commands shown in this tutorial.

top.

Construct the ConnectionManager-class and verify if the connection was successful:

Before the class ConnectionManager can be constructed, it has to be defined in the base-class JSBS_StartFrame.

The construction of the class JSBS_DB_ConnectionManager requieres only a few lines of code in the Start-Frame (CommandCenter, class JS_ErrDB_CommandCenter ).

The implemented code does not lead to any visible result till now.
A verification that can be done, is to check against absence of errors when constructing the ConnectionManager.

top.

Next Step: