Java SQL Table Column getIndexName(Connection conn, String table, String column)

Here you can find the source of getIndexName(Connection conn, String table, String column)

Description

Returns the name of the index for the specified column in the specified table.

License

Open Source License

Declaration

public static String getIndexName(Connection conn, String table, String column) throws SQLException 

Method Source Code

//package com.java2s;

import java.sql.Connection;

import java.sql.ResultSet;
import java.sql.SQLException;

public class Main {
    /**/*ww w  .  j  ava 2  s  . co m*/
     * Returns the name of the index for the specified column in the specified table.
     */
    public static String getIndexName(Connection conn, String table, String column) throws SQLException {
        ResultSet rs = conn.getMetaData().getIndexInfo("", "", table, false, true);
        while (rs.next()) {
            String tname = rs.getString("TABLE_NAME");
            String cname = rs.getString("COLUMN_NAME");
            String iname = rs.getString("INDEX_NAME");
            if (tname.equals(table) && cname.equals(column)) {
                return iname;
            }
        }
        return null;
    }
}

Related

  1. getColumnValue(ResultSet rs, ResultSetMetaData rsmd, int colIndex)
  2. getColumnValue(String column, String defaultValue, Map columnIndexMap, ResultSet res)
  3. getColumnValueFromResultSet(int columnIndex, int argType, ResultSet rs)
  4. getColunmNames(ResultSetMetaData rsmd)
  5. getIndexColumns(Connection connection, String schema, String table, String indexName)
  6. getRange(Connection C, String table, String column)
  7. hasColumn(final ResultSet row, final String columnName)
  8. hasColumn(ResultSet rs, String columnName)
  9. hasColumn(ResultSet rs, String columnName)