Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / JavaBeans / March 2004

Tip: Looking for answers? Try searching our database.

JDBC Transactions involving more than one database?

Thread view: 
Larry - 04 Mar 2004 15:04 GMT
Hi,

I'm building a data synchronization process that must be contained
within a transaction.  Tables from two different databases (Oracle and
Informix) will be updated during the process.  I'm thinking I can't do
this with JDBC type transactions since they are based on the Connect
type object and it can only handle transactions from one database
(unless they could be nested somehow?).

Would EJB transactions be the best way to go?  If so, please explain
why and how.....thnx!

Environment:
WebLogic 8.1 SP2
JRE 1.4.1
Oracle 9.2
Informix 9.3

Larry
Víctor - 04 Mar 2004 17:16 GMT
Hi!
Don't worry, you can use two or more transactional resources (two
database conenctions in your case) and roll back them all. Don´t nest
them, Weblogic will say commit or rollback to every TX resouce included
in your transaction.
I have not had any experience on threating two database connections but
I have had this managing one database and one JMS connection committing
or rolling back both.

> Hi,
>
[quoted text clipped - 15 lines]
>
> Larry
Happyslayer - 05 Mar 2004 06:21 GMT
> Hi,
>
[quoted text clipped - 15 lines]
>
> Larry

I've had experience with this--ported 40,000 records from one database (and
format) into another.

All you have to do is get two connections (conn1 and conn2, one for each
database), and simply do the reading/writing in-between.

Something along these lines:

ResultSet rs1 = conn1.executeQuery(sqlString1);
PreparedStatement stmt =  conn2.prepareStatement(sqlString2);
while (rs.next()) {

   stmt.setInt(1, rs.getInt(1));
   //repeat as necessary, getting integers, doubles, Strings, booleans, etc

   stmt.addBatch(); //suggest using batch updates for larger transactions
}
int i = stmt.executeUpdate();

Just don't forget to close your connections, catch Exceptions, etc...typical
cleaning up.

Hope this helps--worked fine for me.

As an aside, I created a couple of beans to handle "translating" the data
from one format into another...worked pretty good.

Let us know how it turns out.

Happyslayer
Larry - 06 Mar 2004 13:38 GMT
Thnx for the feedback....I do have a little experience with EJB's, but it
doesn't look like I have to go there.

> Hi,
>
[quoted text clipped - 15 lines]
>
> Larry


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.