Java Reference
In-Depth Information
od and pass a
false
value. As you can see in the solution to this recipe, the
setAutoCommit()
method is called passing a
false
value, the database state-
ments are executed. Doing so will cause all the database statement changes to be tem-
porary until the
Connection
object's
commit()
method is called. This provides
you with the ability to ensure that all the statements execute properly before issuing
commit().
Take a look at this transaction management code that is contained within
the
main()
method of the
TransactionExample
class within the solution to this
recipe:
boolean successFlag = false;
...
CreateConnection createConn = new CreateConnection();
conn = createConn.getConnection();
conn.setAutoCommit(false);
queryDbRecipes();
successFlag = insertRecord(
"13-6",
"Simplifying and Adding Security with
Prepared Statements",
"Working with Prepared Statements",
"Recipe Text");
if (successFlag == true){
successFlag = insertRecord(
null,
"Simplifying and Adding Security with Prepared
Statements",
"Working with Prepared Statements",
"Recipe Text");
}
// Commit Transactions
if (successFlag == true)
conn.commit();
else
conn.rollback();
conn.setAutoCommit(true);