是否有用于比较数据库模式的 Java API

发布于 2024-09-14 17:42:05 字数 145 浏览 3 评论 0原文

我想比较

  • 列是否包括数据类型和长度/精度。
  • 两个数据库模式中的索引及其列
  • 约束

是相同的。

有这样的东西可用吗?也许来自数据库迁移管理工具之一?

I'd like to compare if

  • tables
  • columns including datatypes and length/precision.
  • indexes and their columns
  • constraints

in two database schemas are identical.

Is there anything like this available? Maybe from one of the database migration managing tools?

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

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

发布评论

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

评论(4

没有你我更好 2024-09-21 17:42:05

我不知道我使用的模式比较的高级 API DatabaseMetaData 找到差异并不难,因为要检索所有表,您可以执行以下操作:

DatabaseMetaData meta = con.getMetaData();
  ResultSet res = meta.getTables(null, null, null, 
     new String[] {"TABLE"});
  System.out.println("List of tables: "); 
  while (res.next()) {
     System.out.println(
        "   "+res.getString("TABLE_CAT") 
       + ", "+res.getString("TABLE_SCHEM")
       + ", "+res.getString("TABLE_NAME")
       + ", "+res.getString("TABLE_TYPE")
       + ", "+res.getString("REMARKS")); 
  }
  res.close();

以下方法对于您的意图也很重要:

getColumns(String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern) 
getExportedKeys(String catalog, String schema, String table)
getIndexInfo(String catalog, String schema, String table, boolean unique, boolean approximate) 
getPrimaryKeys(String catalog, String schema, String table) 

I don't know a high level API for schema comparison I used DatabaseMetaData it's not to hard to find differences i.g to retieve all tables you can do something like this:

DatabaseMetaData meta = con.getMetaData();
  ResultSet res = meta.getTables(null, null, null, 
     new String[] {"TABLE"});
  System.out.println("List of tables: "); 
  while (res.next()) {
     System.out.println(
        "   "+res.getString("TABLE_CAT") 
       + ", "+res.getString("TABLE_SCHEM")
       + ", "+res.getString("TABLE_NAME")
       + ", "+res.getString("TABLE_TYPE")
       + ", "+res.getString("REMARKS")); 
  }
  res.close();

The following methods are also important for your intention:

getColumns(String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern) 
getExportedKeys(String catalog, String schema, String table)
getIndexInfo(String catalog, String schema, String table, boolean unique, boolean approximate) 
getPrimaryKeys(String catalog, String schema, String table) 
妄司 2024-09-21 17:42:05

SchemaCrawler 提供了一个 Java API,它将数据库元数据呈现为普通的 Java 对象。虽然没有 API 来比较数据库元数据对象,但 SchemaCrawler 会使用标准 diff 工具生成旨在进行 diff 的文本(文本、JSON、CSV、HTML)输出。

Sualeh Fatehi,SchemaCrawler

SchemaCrawler provides a Java API that presents database metadata as plain-old Java objects. While there is no API to compare the database metadata objects, but SchemaCrawler produces text (text, JSON, CSV, HTML) output that is designed to be diff-ed, using standard diff tools.

Sualeh Fatehi, SchemaCrawler

简美 2024-09-21 17:42:05

LiquiBase 具有 数据库差异。但我不知道是否有API,或者只是工具。

LiquiBase has database diff. But I don't know if there is an API, or just the tool.

彩扇题诗 2024-09-21 17:42:05

JDBC 是唯一处理数据库的 Java API。

您必须连接到两者,获取它们各自的 DatabaseMetaData,然后比较两者。

JDBC is the only Java API that deals with databases.

You'd have to connect to both, get their respective DatabaseMetaData, and compare the two.

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