MySQL Database JDBC


JDBC Project Description

The remaining sections in this chapter will present and discuss JDBC concepts in the context of an extended programming example that implements an employee training management system.

Overall System Architecture

The architecture diagram for this system is shown in figure 21-12.

image from book
Figure 21-12: Employee Training Management System Architecture Diagram

Referring to figure 21-12 — an applet will execute in a client-side browser and communicate via the internet using RMI with a server application running on a remote host. The server application will utilize JDBC to connect to a MySQL database running on the same machine.

Recall, if you will, the discussion from chapter 19 concerning the logical and physical distribution of networked applications. The architecture presented above could easily be arranged so the database resides on its own computer or, for testing purposes, all three components could execute on the same computer as well.

Detailed System Architecture

Figure 21-13 shows a detailed class diagram for the server-side components.

image from book
Figure 21-13: Server-Side Component Class Diagram

Referring to figure 21-13 — the DBServerApp class is the main application class for the server-side component of the employee training management system. The DBServerApp class depends upon the Persister and the DBServerProperties classes.

The Persister class is an RMI component that uses JDBC to connect to an instance of a MySQL database. The Persister class will translate RMI method calls it receives from the applet into JDBC calls to the employee training database. The Persister class also depends upon the DBServerProperties class.

Figure 21-14 shows the class diagram for the client-side applet component.

image from book
Figure 21-14: Client-Side Component Class Diagram

Referring to figure 21-14 — the EmployeeTrainingApplet class depends upon the PersisterInterface. It contains two dialogs: AddNewEmployeeDialog and AddTrainingRecordDialog. What is not shown in the diagram is the inheritance relationship between EmployeeTrainingApplet and JApplet, and the two dialogs and JDialog.

Role Of The Persister Class

The Persister class is the key component on the server-side. It implements PersisterInterface which is given in example 21.12 below.

Example 21.12: PersisterInterface.java

image from book
 1     package com.pulpfreepress.dbserver; 2 3     import java.rmi.*; 4     import java.util.*; 5     import com.pulpfreepress.business_objects.*; 6 7     public interface PersisterInterface extends Remote { 8       public Vector queryByLastName(String last_name) throws RemoteException; 9       public void addNewEmployee(Employee emp) throws RemoteException; 10      public void addTrainingRecord(EmployeeTraining et) throws RemoteException; 11      public Employee getEmployeeTrainingRecords(Employee emp) throws RemoteException; 12    }
image from book

Referring to example 21.12 — PersisterInterface specifies four methods: queryByLastName(), addNewEmployee(), addTrainingRecord(), and getEmployeeTrainingRecords(). The types Employee and EmployeeTraining are classes that were created to represent Employee and EmployeeTraining objects respectively. These classes, along with the project’s package structure, will be discussed in detail below. For now I just want you to be aware that these four methods specified by PersisterInterface represent the total sum of functionality of the employee training management system. That is, new employee records can be created, the database can be searched for employees by last name, new employee training records can be added, and all of an employee’s training records can be retrieved. It is the role of the Persister class to deliver this functionality.

Quick Review

In this section I presented an overall architectural view of the employee training management system that will be implemented using Java applet and JDBC technology. It is time now to discuss MySQL, relational database, SQL, and JDBC concepts in more detail to set the stage for your understanding of the project and its code.




Java For Artists(c) The Art, Philosophy, and Science of Object-Oriented Programming
Java For Artists: The Art, Philosophy, And Science Of Object-Oriented Programming
ISBN: 1932504052
EAN: 2147483647
Year: 2007
Pages: 452

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net