Java Reference
In-Depth Information
To Create a Primary Key Index on an Existing Table
1. Enter lines 123 through 136 as shown in Figure 11-17 on page 711.
An index for the UserStocks table is created and designated as the primary
key (Figure 11-27). The WITH keyword is used to declare the index options,
such as PRIMARY and DISALLOW NULL.
compound (two
fields) primary key
index on existing
table
FIGURE 11-27
The tables and their relationships in the StockTracker database now are
defined. Normally, the Statement object no longer would be needed and would
be closed at this point. The Statement object, however, will be used later to verify
the initial data added to the database, after which it will be closed. In order for
the Stock Tracker application to use the database, one valid administrative user
record must exist. This is a result of the application design, requiring that only
an administrative user can add a new user to the database. By using the utility
program to add initial data for a generic administrative user, the Stock Tracker
application can be used later to either change the password for the administra-
tive user, or add a new administrative user and delete the initial generic user,
thus providing for greater data security.
Creating and Executing a Prepared Statement
Microsoft Access is a relational database, allowing the capability to define
relationships between tables via fields, but it does not support manipulation of
objects in a similar manner. Therefore, data in a user record is stored as individ-
ual fields in the database so those fields can be used when selecting records,
defining keys, and obtaining results. Consequently, a User object, even though
used in the application, is not stored as an object in the database. The user pass-
word field in the user record, however, also is an object. It can be stored in the
database as an object because it is not necessary for the DBMS to be able to
access the components of a Password object directly. Rather, this object will be
serialized, as discussed earlier, and then written to the database. On retrieval, this
data will be deserialized and the Password object reconstructed.
 
Search WWH ::




Custom Search