Jdbc – get index meta data

ResultSet tables = metaData.getTables(catalog, schema, tableName, null);

// extract the tablenames

for (String tableName : tablenames) {

// ResultSet – each row is an index column description

ResultSet indexes = metaData.getIndexInfo(catalog, schema, tableName, false, false);

try {


EtlIndexMeta meta = new EtlIndexMeta();


while (indexes.next()) {


// existing meta data


String indexName = indexes.getString(“INDEX_NAME”);


String indexTableName = indexes.getString(“TABLE_NAME”);


boolean nonUnique = indexes.getBoolean(“NON_UNIQUE”);


String columnName = indexes.getString(“COLUMN_NAME”);


String direction = indexes.getString(“ASC_OR_DESC”);


if (indexName != null) {

meta.withIndexName(indexName);

}


if (indexTableName != null) {

meta.withTableName(indexTableName);

}


if (!nonUnique) {

meta.withUnique(true);

}

meta.withIndexName(indexName);


if (columnName != null) {

meta.withColumnName(columnName);

}


if (direction != null) {

meta.withDirection(direction.equals(“A”) ? Direction.ASC : Direction.DESC);

}

}

} finally {

indexes.close();

}

https://docs.oracle.com/javase/7/docs/api/java/sql/DatabaseMetaData.html#getIndexInfo(java.lang.String,%20java.lang.String,%20java.lang.String,%20boolean,%20boolean)