File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes How to handle transactions when two different databases are involved. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "How to handle transactions when two different databases are involved." Watch "How to handle transactions when two different databases are involved." New topic
Author

How to handle transactions when two different databases are involved.

NareshAnkuskani Kumar
Ranch Hand

Joined: Sep 15, 2005
Posts: 76
consider two tables namely Table-A and Table-B part of two different databases namely ORACLE and MYSQL.

Now the project requirement is updating the Table-A(ORACLE) and Table-B (MYSQL) as one transaction. i.e. either update both the tables or rollback both the tables.

Now my question is how could i handle this situation using JDBC(Type-4) driver.Because i think at a time only one JDBC driver can be loaded into the JVM.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

You need to look at JTA/JTS and distributed transactions. EJB containers tend to take care of this for us automagically.
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
You need to use distributed (global) transactions. I have no idea if this is possible without an EJB server but, even if it is, this is one case where the set up and operation would be so much easier with such a server. An EJB server would, amongst other things, bootstrap the XA resources into a it's transaction manager, manage the connection pools via the data sources and manage the global transactions.

You will need to use XA drivers, XA-configured databases and data sources enabled for global transactions. Is there a suitable driver for MySQL?


SCJP 1.4, SCWCD 1.3, SCBCD 1.3
 
jQuery in Action, 2nd edition
 
subject: How to handle transactions when two different databases are involved.
 
Similar Threads
Doubt regarding joins in SQL...
i am using orcale, mysql databases , if i use context.xml i can get datasource only for one db
Comparing two tables of different database
i am using orcale, mysql databases , if i use context.xml i can get datasource for only one db
Copy data from Oracle Database to Access Database in a servlet