This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes OO, Patterns, UML and Refactoring and the fly likes Regarding a batch process design Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "Regarding a batch process design" Watch "Regarding a batch process design" New topic

Regarding a batch process design

Deepa Natrajan

Joined: Dec 14, 2003
Posts: 10
Hi EveryBody
I am new to design though working in java for 2 years.
I have to write a batch process to synchronize two tables.
Simple solution is to make a class and read data from both tables and compare.
Another solution i thougt is to have a seperate classes for table1,table2.Populate the classes with data in constructor.
Write another class which uses the above classes to compare.
Please suggest me whether i am approacingh in proper way.
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Most of the classes you need for DB work come from JDBC. If the two tables are in one database instance, you can just do the appropriate queries and wind up with two ResultSet objects to compare. I've done the same table in two database instances before, and built a little wrapper to hold the connection and execute a query for one database. Then I just make one instances of my class for each database. See if this kind of thing makes sense:

What kind of comparison do you have to do? There is a common algorithm for comparing two sorted lists to detect rows on db1 only or db2 only or matching keys and different data, etc. If that sounds like your problem I can post more.

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Deepa Natrajan

Joined: Dec 14, 2003
Posts: 10
Hi James
Thanks for the reply.
Yes i am looking for the similar thing only.
I need to compate a table in localDB(TABLE L) with a table in globalDB(TABLE M) and update localDB if there is any new entris or change in values found in globalDB.
Thanks and Regards
Kyle Brown
Ranch Hand

Joined: Aug 10, 2001
Posts: 3892
Not that it's my place to do this, but might I suggest that the kind of row-by-row comparison you're suggesting here is a REALLY BAD IDEA. Not only is it terribly wasteful of resource, but it's horrendously slow! There are database tools for doing this that are much more efficient -- they are based on the idea of taking the transaction log from one database and re-executing it on the second database.
Before you try doing this in Java, involve your DBA's and see if they don't already have a synchronization tool for this. If not, it's probably a good idea to invest in one.

Kyle Brown, Author of Persistence in the Enterprise and Enterprise Java Programming with IBM Websphere, 2nd Edition
See my homepage at for other WebSphere information.
Have you checked out Aspose?
subject: Regarding a batch process design
It's not a secret anymore!