Java Reference
In-Depth Information
Introduction
Previously, you were introduced to applications that were used simply to
test the functionality of a reusable Password class, as well as a hierarchy of
PasswordException classes. Application data, such as users, passwords, and
their respective lists of stocks, were stored in memory and had to be entered
each time the test programs were run. In a more realistic application, such data
would be entered once and stored in a database for later retrieval and manipu-
lation.
In this chapter, you will learn how to store and access data in a relational
database. A relational database maintains data in tables, allowing relation-
ships between the tables to be specified, and typically is controlled by a ven-
dor-specific software called a database management system (DBMS), as you
previously learned. A database table provides a grouping of related data in
terms of rows and columns, much as with any table of data, even on a printed
page. Fortunately, Java makes using databases fairly simple through JDBC™.
JDBC provides an API for database-independent connectivity between the Java
programming language and a wide range of tabular data sources, including
relational databases. Although often perceived as an acronym for Java Database
Connectivity, officially, JDBC is a trademarked name, not an acronym; it sim-
ply is JDBC. Through JDBC, Java programs can issue Structured Query
Language ( SQL ) statements to manipulate the database. SQL provides a fairly
standard set of commands to create, update, delete, and query relational data-
bases with relative simplicity. In this chapter, you will learn how to set up a
Microsoft Access database as a data source and how to use JDBC in Java to cre-
ate and delete the table structures within the database. Finally, you will learn
how to create, update, delete, and list data in that database using SQL com-
mands in Java through JDBC.
Chapter Eleven — The Stocktracker Data Access
Class
An application for MoneyMark Trading is being developed that expands on the
program created in Chapter 10 that verified users through a log on process and
then allowed them to track their stock holdings. The new program has similar
functionality, but will retain user and stock information in a database. The
Password class already developed will be enhanced so Password objects can be
saved to a database. This application will make use of a separate class to access
the database and then will present the data to the user in a GUI format.
This chapter presents some database design concepts, and then illustrates
how to complete three tasks necessary to support the GUI Stock Tracker applica-
tion. The majority of what is created in this chapter will have no visible result to
the user, but will support the GUI application supplied on the Data Disk.
As a result of the type of DBMS being used, the first task is to create the
environment for the database (Figure 11-1a). This requires using an administra-
tive utility accessed through the Windows Control Panel. The second task is to
create the internal structure for the database and insert an initial user record into
the database (Figure 11-1b). A new utility program will create this structure and
initialize the database. For the purpose of this program, a simple console user
Search WWH ::




Custom Search