Professional Documents
Culture Documents
Objectives
Cloudscape
Pure-Java embedded database management system.
Installing Cloudscape
Type java jar
D:\software\Cloudscape513\cloudscape_eval_513.jar
to begin the installation process
Figure 26.2 Options to view the release notes. (Courtesy of IBM Corporation.)
Figure 26.4 Accepting the Cloudscape license agreement. (Courtesy of IBM Corporation.)
Figure 26.6 Choosing the default setup type. (Courtesy of IBM Corporation.)
Application Requirements
A local bank has asked you to create a prototype automated teller machine (ATM)
application to access a database that contains sample customer records. Each
record consists of an account number, Personal Identification Number (PIN), first
name and balance amount. For testing purposes, valid account numbers will be
provided in a JComboBox. The ATM application should allow the user to log in to
an account by providing a valid PIN. Once logged in, the user should be able to
view the account balance and withdraw money from the account (if the account
contains sufficient funds). If money is withdrawn, the application should update the
database.
Displays instructions
and messages to the user
JComboBox is disabled
Balance displays
in JTextArea
Display the
withdrawal amount
Displays instructions
and messages to the user
JComboBox is enabled
When the user clicks the Enter JButton to submit the PIN
Search the database for the account numbers corresponding account information
If the user provided a correct PIN
Clear the JTextField
Disable the Enter Jbutton
Disable the keypad Jbuttons
Enable the Balance and Withdraw Jbuttons
Display the status to the user
Else
Clear the JTextField
Prompt the user to enter a valid PIN
When the user clicks the Balance Jbutton
Display the balance
Figure 26.22 ACE table for the ATM application (Part 1 of 6).
Figure 26.22 ACE table for the ATM application (Part 3 of 6).
26.5 SQL
accountNumber firstName
12548693 John
24578648 Susan
35682458 Joseph
45632598 Michael
52489635 Donna
55698632 Elizabeth
69857425 Jennifer
71869534 Al
88965723 Ben
98657425 Bob
WHERE Clause
Specify the selection criteria for a query
Only rows that satisfy the criteria will be selected
Combined with a SELECT statement
General form:
SELECT columnName1, columnName1,
FROM TableName WHERE criteria
Example
SELECT pin, firstName, balanceAmount
FROM accountInformation
WHERE accountNumber = 12548693
Figure 26.25 Selecting the pin, firstName and balanceAmount for the person with
accountNumber 12548693
UPDATE Statement
Modify data in a table
Basic form:
UPDATE TableName
SET columnName1 = value1, columnName2 = value2
WHERE criteria
TableName specifies table to update
SET keyword is followed by list of column name/value pairs
WHERE clause determines which rows to update
Example
UPDATE accountInformation
SET balanceAmount = 1000
WHERE accountNumber = 12548693
main method
Command line arguments
Passed to main as String array args
Length of args
Standard output object
System.out
Display text in the Command Prompt window
JDBC API
Communicate and manipulate databases
JDBC Driver
Provided by a DMNS vendor
Enable Java applications to access a particular database
Importing the
java.sql package
java.sql package
Perform database processing
Connection object
Manages connection between Java application and database
Allows applications to create SQL statements
Statement object
Enables applications to execute SQL statements
ResultSet object
Returned by executing a query
Contain rows and columns selected
Rows of table returned in sequence
One ResultSet per Statement
Declaring instance
variables for managing
the database connection
Connecting to a database
Load database driver
forName method of class Class
DriverManager class
Manages JDBC drivers and establishes connections to
databases
getConnection method connects to database
JDBC URL
Form: protocol:subprotocol:subname
Specifies protocol and subprotocol for communication
and name of database
Protocols and subprotocols define how data is
transferred between a Java application and a database
Close myResultSet to
release database resources