Java Reference
In-Depth Information
Section 24.10 Transaction Processing
• Transaction processing (p. 1098) enables a program that interacts with a database to treat a da-
tabase operation (or set of operations) as a single operation—known as an atomic operation
(p. 1099) or a transaction (p. 1099).
• At the end of a transaction, a decision can be made to either commit or roll back the transaction.
• Committing a transaction (p. 1099) finalizes the database operation(s)—inserts, updates and de-
letes cannot be reversed without performing a new database operation.
• Rolling back a transaction (p. 1099) leaves the database in its state prior to the database operation.
• Java provides transaction processing via methods of interface Connection .
•Method setAutoCommit (p. 1099) specifies whether each SQL statement commits after it com-
pletes (a true argument) or whether several SQL statements should be grouped as a transaction.
• When autocommit is disabled, the program must follow the last SQL statement in the transac-
tion with a call to Connection method commit (to commit the changes to the database; p. 1099)
or Connection method rollback (to return the database to its state prior to the transaction;
p. 1099).
•Method getAutoCommit (p. 1099) determines the autocommit state for the Connection .
Self-Review Exercise
24.1
Fill in the blanks in each of the following statements:
a)
The international standard database language is
.
b)
A table in a database consists of
and
.
c)
Statement objects return SQL query results as
objects.
d)
The
uniquely identifies each row in a table.
e)
SQL keyword
is followed by the selection criteria that specify the rows to
select in a query.
f)
SQL keywords
specify the order in which rows are sorted in a query.
g)
Merging rows from multiple database tables is called
the tables.
h)
A(n)
is an organized collection of data.
i)
A(n)
is a set of columns whose values match the primary-key values of an-
other table.
j)
method
is used to obtain a Connection to a database.
k)
Interface
helps manage the connection between a Java program and a data-
base.
l) A(n) object is used to submit a query to a database.
m) Unlike a ResultSet object,
and
objects are scrollable and updat-
able by default.
n)
, a disconnected RowSet , caches the data of a ResultSet in memory.
Answers to Self-Review Exercise
24.1 a) SQL. b) rows, columns. c) ResultSet . d) primary key. e) WHERE . f) ORDER BY . g) joining.
h) database. i) foreign key. j) DriverManager , getConnection . k) Connection . l) Statement .
m) JdbcRowSet , CachedRowSet . n) CachedRowSet .
Exercises
24.2 (Query Application for the books Database) Using the techniques shown in this chapter, de-
fine a complete query application for the books database. Provide the following predefined queries:
 
 
Search WWH ::




Custom Search