从oracle迁移到MySQL期间如何使用Java比较两者之间的数据

发布于 2024-11-14 08:18:57 字数 164 浏览 5 评论 0原文

我已使用 MySQL Migration Toolkit 作为 POC 将数据从 Oracle 迁移到 MySQL。现在我想用Java比较不同数据库的相同表之间的数据。

我已经完成了两个数据库中表的简单总行数。但我想检查两个表的每一行,以便可以计算出任何 Oracle 表发布或迁移期间的任何更新。

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 .

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风追烟花雨 2024-11-21 08:18:57

这可能听起来有点傻,但是一个只读取两个数据库并比较数据的简单程序怎么样?

您可以编写一个包含一行中所有数据的类,重写 equals() 和 hashCode(),然后读取两个表并使用创建的类对它们进行比较。

public class MyRow {
    int someVal;
    String someOtherVal;
    // etc
    public boolean equals(Object obj) {} // implement this
    public int hashCode(){} // implement this
}

然后在您的程序中:

List<MyRow> mysqlRows = readMysql();
List<MyRow> oracleRows = readOracleRows();
for (MyRow mysqlRow : mysqlRows) {
    if (!mysqlRow.equals(oracleRows.get(index)) {
        // log error
    }
}

当然,如果行数很大并且内存使用量是一个问题,您可能需要考虑一次一行读取表。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文