简体   繁体   English

Java:JDBC获取列约束

[英]Java: JDBC get Column Constraints

Currently using JDBC I am able to retrieve column information from tables in my database. 当前使用JDBC,我能够从数据库中的表中检索列信息。 I am able to retrieve the name, column type and if the column allows null values. 我能够检索名称,列类型以及该列是否允许空值。

However I'm trying to retrieve if the column has any constraints, specifically the Unique constraint. 但是,我试图检索该列是否具有任何约束,特别是唯一约束。

Code: 码:

rs = databaseMetaData.getColumns(null, null, tableName, null);
while (rs.next()) {
    String columnName = rs.getString(4);
    String TypeName = rs.getString(6);
    String nullable = rs.getString(18);

Column uniqueness is typically handled by an index. 列唯一性通常由索引处理。 Try the DatabaseMetData.getIndexInfo() method. 尝试使用DatabaseMetData.getIndexInfo()方法。 You also might want to check the DatabaseMetaData.getPrimaryKeys() results. 您可能还需要检查DatabaseMetaData.getPrimaryKeys()结果。

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

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