12.3. Transactions

You may recall from ColdFusion working with the <cftransaction> tag, which allows you to create a logical group of statements to be sent to a database. They are meant to all be executed, and if one or more cannot be executed, any executed statements must be undone. That is, having specified a series of SQL statements as a transaction group, the entire group can be rolled back if necessary. They also allow you to undo an operation if an exception occurred during a database query. Transaction blocks are defined like this in ColdFusion:

 <cftry> <cftransaction action = "begin"> <cfquery name = q" datasource = "#request.dsn#"> INSERT INTO Products (productName, price) VALUES ('#form.productName#', 75); </cfquery> <cfcatch type="DATABASE"> ...

Get Java™ for ColdFusion® Developers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.