Databases Reference
In-Depth Information
closeResultSet(resultSet);
closeStatement(stmt);
closeStatement(prepStmt);
}
}
See “Managing Commits in Transactions,” page 22, for information on when
to commit work if you've turned off auto-commit mode.
Choosing the Right Transaction Model
Which type of transaction should you use: local or distributed? A local transac-
tion accesses and updates data on a single database. A distributed transaction
accesses and updates data on multiple databases; therefore, it must be coordi-
nated among those databases.
Performance Tip
Distributed transactions, as specified by the Java Transaction API (JTA),
are substantially slower than local transactions because of the logging
and network round trips needed to communicate between all the compo-
nents involved in the distributed transaction. Unless distributed transac-
tions are required, use local transactions.
If your application will be deployed on an application server, you also need
to be aware that the default transactional behavior of many Java application
servers is to use distributed transactions. Often, administrators, not developers,
are responsible for deploying the application on the application server and may
choose the default transaction behavior because they don't fully understand the
performance impact of using distributed transactions.
For example, suppose you develop an application that leverages the use of
two different jar files. Each jar file connects to a different database to perform
work that is completely unrelated. One jar file connects to a database and incre-
ments the number of problem tickets in the system. The other jar file connects to
another database to update a customer address. When your application is
deployed, the application server may ask a tuning question similar to, “Is this
component transactional?” The administrator thinks it over and decides that the
 
Search WWH ::




Custom Search