During migration from oracle to MySQL how to compare data between two using Java
I have migrated data from Oracle to MySQL using MySQL Migration Toolkit as POC. Now I want to compare data between same tables of different databases with Java.
开发者_如何学编程I have done the simple total no of rows of the tables in two database. But I want to check each and every row of two tables so that any update in any oracle table post or during migration can be figured .
This might sound a bit silly, but how about a simple program which just reads both databases and compares the data?
You could write a class containing all the data from one row, override equals() and hashCode(), then read both tables and compare them using the created class.
public class MyRow {
int someVal;
String someOtherVal;
// etc
public boolean equals(Object obj) {} // implement this
public int hashCode(){} // implement this
}
Then in your program:
List<MyRow> mysqlRows = readMysql();
List<MyRow> oracleRows = readOracleRows();
for (MyRow mysqlRow : mysqlRows) {
if (!mysqlRow.equals(oracleRows.get(index)) {
// log error
}
}
Of course, you might want to consider reading the tables a row at a time, if the amount of rows is massive and memory usage is an issue.
精彩评论