J.E.D.I
• loading the appropriate driver • connect to the database
The sequence diagram of JDBC Initialization is shown in Figure 4.24.
The DBClass loads the appropriate driver by calling the getConnectionurl, user, password
. This method seeks to establish a connection to the given database URL. The
DriverManager
attempts to select an appropriate driver from the set of registered JDBC drivers.
2. JDBC Create. This behavior creates a record. It executes the INSERT-statement of
SQL. It assumes that a connection has been established. The sequence diagram is shown in Figure 4.25.
Sequence Diagram Flow Description:
• The PersistencyClient asks the DBClass to create a new class. • The DBClass creates a new instance of the PersistentClass new and assigns
Software Engineering 161
Figure 4.24 JDBC Initialization
Figure 4.25 JDBC Create
J.E.D.I
values to the PersistentClass. • The DBClass, then, creates a new Statement using the createStatement of the
connection
. Normally, this is an INSERT-statement in SQL.
• The Statement is executed via executeUpdateString:int method. A record is
inserted in the database.
3. JDBC Read. This behavior retrieves records from the database. It executes the
SELECT-statement. It also assumes that a connection has been established. The sequence diagram is shown in Figure 4.26.
• The PersistencyClient asks the DBClass to retrieve records from the database. SearchCriteria
string qualifies what records to return.
• The DBClass creates a SELECT-statement Statement using the createStatement method of Connection.
• The Statement is executed via executeQuery and returns a ResultSet. • The DBClass instantiates a PersistentClassList to hold the records represented in
the ResultSet. • For each record in the ResultSet, the DBClass instantiates a PersistentClass.
• For each field of the record, assign the value of that field getString to the appropriate attribute in the PersistentClass setData.
• After getting all data of the record and mapping it to the attributes of the
PersistentClass , add the PersistentClass to the PersistentClassList.
4. JDBC Update. This executes the UPDATE-statement of SQL. It changes the values
of an existing record in the database. It assumes that connection has been established. The sequence diagram is shown in Figure 4.27.
Software Engineering 162
Figure 4.26 JDBC Read
J.E.D.I
• PersistencyClient asks the DBClass to update a record. • The DBClass retrieves the appropriate data from the PersistentClass. The
PersistentClass must provide access routine for all persistent data that the DBClass
needs. This provides external access to certain persistent attributes that would have been otherwise have been private. This is a price that you pay to pull the persistent
knowledge out of the class that encapsulates them.
• The Connection will create an UPDATE-Statement. • Once the Statement is built, the update is executed and the database is updated with
the new data from the class.
5. JDBC Delete. This executes the DELETE-statement of SQL. It deletes records in the