Java Reference
In-Depth Information
Distributed Transaction Management
The primary difference between using a regular connection and using a connection
intended for distributed transactions is that all distributed transactions are committed
or rolled back by a separate transaction manager in the middle tier. So the application
should not do anything that can interfere with what the transaction manager is doing.
This means that application code should never call these methods:
 
Connection.commit
 
Connection.rollback
 
Connection.setAutoCommit(true)
A connection created for distributed transactions can, of course, also be used for
nondistributed transactions, in which case these restrictions do not apply.
Note
A Connection object that can be used for distributed transactions has its
auto-commit mode turned off by default, unlike a regular connection for
which the default is to have its auto-commit mode turned on.
Connection
A Connection object represents a connection with a database. A connection session
includes the SQL statements that are executed and the results that are returned over
that connection. A single application can have one or more connections with a single
database, or it can have connections with many different databases.
Opening a connection
The standard way to establish a connection with a database is to call the method
getConnection() on either a DataSource or a DriverManager. The Driver method
connect uses this URL to establish the connection.
A user can bypass the JDBC management layer and call Driver methods directly.
This can be useful in the rare case that two drivers can connect to a database and the
user wants explicitly to select a particular driver. Usually, however, it is much easier to
just let the DataSource class or the DriverManager class open a connection.
Database URLs
A URL (Uniform Resource Locator) is an identifier for locating a resource on the
Internet. It can be thought of as an address. A JDBC URL is a flexible way of
identifying a database so that the appropriate driver recognizes it and establishes a
connection with it. JDBC URLs allow different drivers to use different schemes for
naming databases. The odbc subprotocol, for example, lets the URL contain attribute
values.
Search WWH ::




Custom Search