Java Reference
In-Depth Information
The user can then view different entries by pressing the Previous JButton or Next
JButton , which results in calls to methods previousButtonActionPerformed (lines 241-
250) or nextButtonActionPerformed (lines 253-262), respectively. Alternatively, the
user can enter a number in the indexTextField and press Enter to view a particular entry.
This results in a call to method indexTextFieldActionPerformed (lines 290-306) to dis-
play the specified record.
24.9 Stored Procedures
Many database management systems can store individual or sets of SQL statements in a
database, so that programs accessing that database can invoke them. Such named collec-
tions of SQL statements are called stored procedures . JDBC enables programs to invoke
stored procedures using objects that implement the interface CallableStatement .
CallableStatement s can receive arguments specified with the methods inherited from in-
terface PreparedStatement . In addition, CallableStatement s can specify output param-
eters in which a stored procedure can place return values. Interface CallableStatement
includes methods to specify which parameters in a stored procedure are output parameters.
The interface also includes methods to obtain the values of output parameters returned
from a stored procedure.
Portability Tip 24.6
Although the syntax for creating stored procedures differs across database management sys-
tems, the interface CallableStatement provides a uniform interface for specifying input
and output parameters for stored procedures and for invoking stored procedures.
Portability Tip 24.7
According to the Java API documentation for interface CallableStatement , for maxi-
mum portability between database systems, programs should process the update counts
(which indicate how many rows were updated) or ResultSet s returned from a Call-
ableStatement before obtaining the values of any output parameters.
24.10 Transaction Processing
Many database applications require guarantees that a series of database insertions, updates
and deletions executes properly before the application continues processing the next data-
base operation. For example, when you transfer money electronically between bank ac-
counts, several factors determine if the transaction is successful. You begin by specifying
the source account and the amount you wish to transfer from that account to a destination
account. Next, you specify the destination account. The bank checks the source account
to determine whether its funds are sufficient to complete the transfer. If so, the bank with-
draws the specified amount and, if all goes well, deposits it into the destination account to
complete the transfer. What happens if the transfer fails after the bank withdraws the mon-
ey from the source account? In a proper banking system, the bank redeposits the money
in the source account. How would you feel if the money was subtracted from your source
account and the bank did not deposit the money in the destination account?
Transaction processing enables a program that interacts with a database to treat a
database operation (or set of operations) as a single operation . Such an operation also is known
 
 
 
Search WWH ::




Custom Search