File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes Comparing two tables of different database Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Object Relational Mapping
Reply Bookmark "Comparing two tables of different database" Watch "Comparing two tables of different database" New topic
Author

Comparing two tables of different database

Fidel Edwards
Ranch Hand

Joined: Mar 19, 2008
Posts: 200
Hi,

I have two databases (may be different like MySQL and Oracle OR same Oracle as both DB) as DB1 and DB2. I want to compare a table from both the database. In other words,I want to compare DB1.Table1 and DB2.Table1.
I am thinking of two ideas

  • JDBC Connection : In this I will open two connection (One with MySQL and another with Oracle)and compare all the rows from both of the database.
  • Hibernate : I can also achieve this by comparing objects from both the databases.


  • Can anyone explain me what can be the right way to do it, first one, second one or any other way to do it?

    Thanks in advance !

    This message was edited 1 time. Last update was at by Fidel Edwards



    God Gave Me Nothing I Wanted, He Gave Me Everything I Needed.
    Paul Sturrock
    Bartender

    Joined: Apr 14, 2004
    Posts: 10336

    There are lots of database diffing tools out there, one of these might save you the effort of writing your own.

    If you do want to roll your own, plain old JDBC is probably a better choice. ORMs are not really designed for large scale bulk operations. However, writing something that compares both data and data model is quite a lot of work.


    JavaRanch FAQ HowToAskQuestionsOnJavaRanch
    Fidel Edwards
    Ranch Hand

    Joined: Mar 19, 2008
    Posts: 200
    Thanks Paul for instant response!

    Paul Sturrock wrote:There are lots of database diffing tools out there, one of these might save you the effort of writing your own.

    Can't go with any of the tool as it is the requirement for only one table.

    Paul Sturrock wrote:
    If you do want to roll your own, plain old JDBC is probably a better choice. ORMs are not really designed for large scale bulk operations.

    Since table will contain only 250 odd records at maximum, I can anguish with it. In case of JDBC, I'm creating two connections, selecting data from the both the database and preparing the object . But issue here is the right way to compare objects, when I want to compare the records of all the 20 columns of the table.
    a) Comparator : will contain 20 getters comparisons
    b) toString: will contain prepared list of getters like


    And we will be comparing the objects only like




    what will be the right approach?
     
     
    subject: Comparing two tables of different database
     
    MyEclipse, The Clear Choice

    cast iron skillet 49er

    more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture