Oracle8i JDBC Developer's Guide and Reference Release 3 (8.1.7) Part Number A83724-01 |
|
If you have multiple databases involved in your transaction, you must configure a two-phase commit engine for managing all changes to all databases involved in the transaction. A two-phase commit engine is responsible for contacting all of the databases at the end of the transaction and managing the commit or rollback of all updates to all included databases. Thus, this two-phase commit engine must have access to database links to each database included within the transaction.
To configure for a two-phase commit, your system administrator must do the following:
dblink
option of bindds
for each individual database when binding that database's DataSource
into the namespace.
bindds /test/empDatabase -url jdbc:oracle:thin:@empHost:5521:ORCL
-dstype jta -dblink 2pcToEmp.oracle.com
UserTransaction
into the namespace.
bindut /test/myUT -expprop -url jdbc:oracle:thin:@2pcHost:5521:ORCL
-user SCOTT -password TIGER
Once all of this configuration is complete, your client or server differs from the single-phase commit scenario in the following aspects:
DataSource.getConnection
.
DataSource
objects retrieved must have been bound with a database link from the two-phase commit engine to itself.
Except for the in-session activation rules, the client and the server code is the same. The following example shows a server object that performs an in-session activation to retrieve both the UserTransaction
and DataSource
objects that have been bound locally. So, all that they need to provide is the username and password information for the two-phase commit engine.
//create the initial context. InitialContext ic = new InitialContext (); UserTransaction ut = (UserTransaction)ic.lookup ("/test/myUT"); // lookup the local datasource and a remote database. DataSource localDS = (DataSource)ic.lookup ("/test/localDS"); DataSource remoteDS = (DataSource)ic.lookup ("/test/NewYorkDS"); Connection localConn = localDS.getConnection (); //provide the database username and password in the getConnection method Connection remoteConn = remoteDS.getConnection (SCOTT, TIGER); ... //close the connections localConn.close(); remoteConn.close(); //end the transaction ut.commit();
For a client or a server where the namespace is remote, you must initialize the environment with the authentication information, namespace location, and register the OracleDriver
.
|
![]() Copyright © 1996-2000, Oracle Corporation. All Rights Reserved. |
|