Here you can find the source of getIndexColumns(Connection connection, String schema, String table, String indexName)
Parameter | Description |
---|---|
indexName | name of the index |
public static List<String> getIndexColumns(Connection connection, String schema, String table, String indexName) throws SQLException
//package com.java2s; //License from project: Open Source License import java.sql.*; import java.util.*; public class Main { /**/*www . j a v a 2 s . c o m*/ * Returns list of column names for the specified index * * @param indexName name of the index * @return list of index columns; can return empty list; never NULL */ public static List<String> getIndexColumns(Connection connection, String schema, String table, String indexName) throws SQLException { final Map<Integer, String> columns = new TreeMap<>(); ResultSet rs = null; try { rs = connection.getMetaData().getIndexInfo(null, schema, table, true, false); while (rs.next()) { final String name = rs.getString("INDEX_NAME"); if (name != null && name.equals(indexName)) { columns.put(rs.getInt("ORDINAL_POSITION"), rs.getString("COLUMN_NAME")); } } } finally { closeQuietly(rs); } return new ArrayList<>(columns.values()); } /** * Closes provided {@link ResultSet} without throwing exception * * @param rs {@link ResultSet} to close */ public static void closeQuietly(ResultSet rs) { if (rs != null) { try { rs.close(); } catch (Exception e) { //ignore } } } /** * Closes provided {@link Statement} without throwing exception * * @param statement {@link Statement} to close */ public static void closeQuietly(Statement statement) { if (statement != null) { try { statement.close(); } catch (Exception e) { //ignore } } } /** * Closes provided {@link Connection} without throwing exception * * @param connection {@link Connection} to close */ public static void closeQuietly(Connection connection) { if (connection != null) { try { connection.close(); } catch (Exception e) { //ignore } } } }