Here you can find the source of tableContainsIndex(Connection conn, String table, String column, String index)
public static boolean tableContainsIndex(Connection conn, String table, String column, String index) throws SQLException
//package com.java2s; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; public class Main { /**// w ww .j a v a2s . c om * Returns true if the index on the specified column exists for the specified table, false if * it does not. Optionally you can specifiy a non null index name, and the table will be * checked to see if it contains that specifically named index. <em>Note:</em> the names are * case sensitive. */ public static boolean tableContainsIndex(Connection conn, String table, String column, String index) throws SQLException { boolean matched = false; 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 (index == null) { if (tname.equals(table) && cname.equals(column)) { matched = true; } } else if (index.equals(iname)) { matched = true; } } return matched; } }