Does anyone know how to get the column names of an index that spans multiple columns (see SQL
) via JDBC
? I do know how to get all index columns (see code), but this way I cannot see which columns are linked to a single index.
CREATE TABLE IF NOT EXISTS `foo` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`test1` int(11) NOT NULL,
`test2` int(11) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `test1` (`test1`,`test2`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
DatabaseMetaData md = connection.getMetaData(); // assumed that connection exists
ResultSet rs = md.getIndexInfo(null, dbSchema, "foo", true, false);
while (rs.next()) {
String columnName = rs.getString("COLUMN_NAME");
}