Let's now see a sample program that communicates with two Oracle database instances through an application with XA transaction.
The following is the series of steps to be executed by this program:
- Begin the transaction division on database DB1 and then on DB2.
- Perform a DML query execution on DB1 and then on DB2.
- Complete the transaction execution on DB1 and then on DB2.
- Prepare the completion on DB1 and then on DB2.
- Commit the transaction on DB1 and then on DB2.
The following is the program for XATransaction on two Oracle databases. Don't forget to include ojdbc.jar to your project when you are writing this example:
package distributedtransaction;//You need to import the java.sql package to use JDBC ...