Scott
Scott

Reputation: 29

Java: JDBC get Column Constraints

Currently using JDBC I am able to retrieve column information from tables in my database. 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);

Upvotes: 1

Views: 1178

Answers (1)

jtahlborn
jtahlborn

Reputation: 53694

Column uniqueness is typically handled by an index. Try the DatabaseMetData.getIndexInfo() method. You also might want to check the DatabaseMetaData.getPrimaryKeys() results.

Upvotes: 1

Related Questions