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.
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. Regards Deepa
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
Joined: Dec 14, 2003
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 Deepa
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