Solved

Comparing recordsets in java

Posted on 2011-03-03
5
536 Views
Last Modified: 2012-05-11
I need to compare a few records from 2 different versions of a DB and point out the mismatch if any. What is the best way to do this? Also I need to point out the mismatch in the structure (column name mismatch, additoinal column) of the table if any.
0
Comment
Question by:PearlJamFanatic
  • 4
5 Comments
 
LVL 47

Accepted Solution

by:
for_yan earned 334 total points
Comment Utility
Well, to compare the table structures you'll probably want to use getMetaData method like shown in this link:

http://www.roseindia.net/jdbc/JdbcGetMetadata.shtml

The comparison of ResultSets startegy would probably very much depend
on the suzes of these ResultSets - and how many mismatches you expect to have.
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
If you have rather big tables and really need to caompare them often, I'd consider still
importing one of them into the same database as the other and use
database facilities to compare them, as that will definitel will be more effective.

If you need to do it only once then probably connecting to two databases, making sure
you order your query in the same way  and stepping through ResultSets one by one will
be some kind of the option. The more information you have where you can expect differences, which wouild allow
you to minimize the number of rows you select - the better you are off with the required
resources, times.  Well, it is hard to beleve ther could be one best straeguy in this task for
all different situations you can imagine with respect to sizes of the record sets, type of data, probability of the differences, etc.
If you have effective databases - the less rows you have to select and analyze in
Java code, the more you can do on the server side - the better.


0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility


here you'll find  two more considerations
http://www.thatsjava.com/java-essentials/11433/

And again they are appropriate to some cases and may not be so good for other situations.
0
 
LVL 47

Assisted Solution

by:for_yan
for_yan earned 334 total points
Comment Utility
One more thought which occured to me - if those would be
tables on two Oracle databases and tables are big  (I work mostly with Oracle so
it's easier for me to think of Oracle) I would
think it would be more efficient in many cases to make a database link between
the two DB and try to use as much as possible Oracle means to compare
the data using SQL or even PL/SQL, and then only try to do in Java those
comparisons which require to fetch less data but may be more sophisticated
from logical point of view and require more flexibility in output, formatting etc.
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 166 total points
Comment Utility
There are two different things there:

a. metadata differences
b. data differences

a. only needs to be done once probably. b. might be better done if you make the rowset into a List of beans first
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

If you don't know how to downgrade, my instructions below should be helpful.
This process describes the steps required to Import and Export data from and to .pst files using Exchange 2010. We can use these steps to export data from a user to a .pst file, import data back to the same or a different user, or even import data t…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now