Java Reference
In-Depth Information
5. Enter lines 258 through 277 as shown in Figure 11-36 on page 737.
TextPad displays the code to rollback the transaction, close the Statement,
and complete the method (Figure 11-50). If the rollback fails, a new
SQLException is thrown.
Connection
rollback() method
static Statement
close() method
FIGURE 11-50
Notice how line 227 calls the method, delUserStocks(), to delete a stock
holding for a user. This method will be written next. The requirements docu-
ment indicates that a stock no longer held by any user should be deleted. It is
possible that when this method is called, the stock holding to be deleted is the
last for this stock. Lines 285 through 287 delete the current stock holding for the
user. To determine if any other users hold this stock, the UserStocks table is
queried in lines 289 through 290. Earlier, you learned that the next() method of
a ResultSet returns true if the next row is valid and false if there are no more
rows. As was done in the MakeDB class, line 292 checks if no users were found to
hold this stock and if there were none, the delStock() method, coded earlier, is
called in line 293. Line 295 closes the local Statement object for this method.
Notice that each of the methods, delUser(), delUserStocks(), and delStock(),
contain a local Statement object. Multiple statements may be opened on a single
connection and, in this case, they all can use the same reference name because
they are local to each method.
The following step enters the code to delete a user stock holding and,
optionally, call a method to delete the stock record if the stock no longer is held
by a user.
 
Search WWH ::




Custom Search