Java Reference
In-Depth Information
}
}
public static void main(String args[]){
DataUpdater inserter = new DataUpdater();
String SQLCommand = "UPDATE CONTACT_INFO "+
"SET STREET = '58 Broadway', ZIP = '10008' "+
"WHERE First_Name = 'Michael' AND "+
"Last_Name ='Corleone';";
inserter.execute(SQLCommand);
}
}
Once again, the basic Java code used to issue the SQL command remains unchanged. To try it out,
compile and execute the example; you should be able to see the modified record in your Contact_Info
Table.
Transaction Management with COMMIT and ROLLBACK
Transaction management refers to the capability of a relational database management system to
execute database commands in groups, known as transactions. A transaction is a group or sequence
of commands, all of which must be executed in order and must complete successfully. If anything goes
wrong during the transaction, the database management system will allow the entire transaction to be
cancelled or "rolled back." If, on the other hand, it completes successfully, the transaction can be
saved to the database or "committed."
A transaction typically involves several related commands, as in the case of a bank transfer. If Client A
orders a transfer of funds to Client B , at least two database-access commands must be executed:
 
Client A's account must be debited.
 
Client B's account must be credited.
If one of these commands is executed but the other is not, the funds will either vanish from Client A's
account without appearing in Client B's account, or, perhaps worse from the viewpoint of the bank, the
funds will be credited to Client B's account without being withdrawn from Client A's account, leaving
the bank in the hole.
This situation obviously becomes dramatically more complicated in the real world, where a large
financial institution, with hundreds or thousands of users all accessing the database at the same time,
can potentially have vast numbers of incomplete transactions active at any given moment.
The solution is to combine logically related commands into groups that are committed as a single
transaction. If a problem arises, the entire transaction can be rolled back and the problem fixed without
serious adverse impact on business operations.
Search WWH ::




Custom Search