简体   繁体   English

使用JDBC获取与一个表相对应的所有外键以及保存这些外键的表

[英]Getting all foreign keys corresponding to a table and the tables that hold those foreign keys with JDBC

I need to get all the foreign keys of a particular table and get the names of the tables containing those foreign keys, is there a simple way to do this using JDBC ? 我需要获取特定表的所有外键,并获取包含这些外键的表的名称,是否有使用JDBC的简单方法?

I know there is a way to do this for a particular database using a query, but I need to get a generic solution using JDBC . 我知道有一种使用查询对特定数据库执行此操作的方法,但是我需要使用JDBC获得通用解决方案。

You need to use DatabaseMetaData.getExportedKeys : 您需要使用DatabaseMetaData.getExportedKeys

Retrieves a description of the foreign key columns that reference the given table's primary key columns (the foreign keys exported by a table). 检索对引用给定表的主键列(由表导出的外键)的外键列的描述。

For example 例如

dbmd.getExportedKeys(null, null, "SOME_TABLE_NAME")

will return a list of all tables and their foreign keys pointing to the primary key of SOME_TABLE_NAME . 将返回所有表及其外键的列表,这些表指向SOME_TABLE_NAME的主键。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM