wood burning stoves 2.0*
The moose likes Distributed Java and the fly likes How to insert data in multiple database. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Distributed Java
Bookmark "How to insert data in multiple database." Watch "How to insert data in multiple database." New topic
Author

How to insert data in multiple database.

raj malhotra
Ranch Hand

Joined: Feb 22, 2007
Posts: 285
Hi
According to the usecase whenever update happen it should update all the dbs in remote place.which are in different geographical locations.Whatever i understood about distributed transaction is:
1.I can configure the Datasource in application server which support global transaction.
2.In my code i need to get the datasource.
3.get a connection.
4.begin transaction.
5.update db
6.end transaction.
But my doubt is i am having just one connection which i got for one db.so i can update that db.Can i use this connection to update other dbs?Is it a global connection.
Can anyone explain me step 5 in details to update multiple db.

Thanks
Raj
Raf Szczypiorski
Ranch Hand

Joined: Aug 21, 2008
Posts: 383
A DataSource is an abstraction of a physical database server and schema / user. It can only connect to a single database. To update 2 databases, you need two datasources.
raj malhotra
Ranch Hand

Joined: Feb 22, 2007
Posts: 285
Then How should i maintain a distributed transaction??
Nitesh Kant
Bartender

Joined: Feb 25, 2007
Posts: 1638

You do not have to do anything "special" to handle a distributed transaction.
Conceptually, in between the begin and end of a transaction whatever you do is inside the ambit of that transaction. Whether you update 2 databases, 1 Database and 1 JMS queue or 100 databases, it does not really matter.
All it matters is that the driver must support distributed transactions i.e. it must be an XA driver.

In case you are using weblogic, this article will give you a good idea.


apigee, a better way to API!
raj malhotra
Ranch Hand

Joined: Feb 22, 2007
Posts: 285
Thanks very much Nitesh
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: How to insert data in multiple database.