List of usage examples for java.sql DatabaseMetaData tableIndexHashed
short tableIndexHashed
To view the source code for java.sql DatabaseMetaData tableIndexHashed.
Click Source Link
From source file:Main.java
public static void main(String[] args) throws Exception { Connection conn = getMySqlConnection(); System.out.println("Got Connection."); Statement st = conn.createStatement(); st.executeUpdate("drop table survey;"); st.executeUpdate("create table survey (id int,name varchar(30));"); st.executeUpdate("insert into survey (id,name ) values (1,'nameValue')"); ResultSet indexInformation = null; DatabaseMetaData meta = conn.getMetaData(); // The '_' character represents any single character. // The '%' character represents any sequence of zero // or more characters. indexInformation = meta.getIndexInfo(conn.getCatalog(), null, "survey", true, true); while (indexInformation.next()) { short type = indexInformation.getShort("TYPE"); switch (type) { case DatabaseMetaData.tableIndexClustered: System.out.println("tableIndexClustered"); case DatabaseMetaData.tableIndexHashed: System.out.println("tableIndexHashed"); case DatabaseMetaData.tableIndexOther: System.out.println("tableIndexOther"); case DatabaseMetaData.tableIndexStatistic: System.out.println("tableIndexStatistic"); default:/*from www. j av a2 s.c o m*/ System.out.println("tableIndexOther"); } } st.close(); conn.close(); }
From source file:com.nextep.designer.sqlgen.helpers.CaptureHelper.java
/** * Converts a JDBC index type code into a neXtep {@link IndexType} enumeration. * //from www . j a v a 2 s. c o m * @param type JDBC code of the index type * @return a corresponding {@link IndexType} */ public static IndexType getIndexType(short type) { switch (type) { case DatabaseMetaData.tableIndexHashed: return IndexType.HASH; case DatabaseMetaData.tableIndexStatistic: case DatabaseMetaData.tableIndexClustered: case DatabaseMetaData.tableIndexOther: default: return IndexType.NON_UNIQUE; } }
From source file:org.apache.ddlutils.task.DumpMetadataTask.java
/** * Dumps the indexes of the indicated table. * //from w w w . j a v a2s .c o m * @param xmlWriter The xml writer to write to * @param metaData The database metadata * @param catalogName The catalog name * @param schemaName The schema name * @param tableName The table name */ private void dumpIndexes(PrettyPrintingXmlWriter xmlWriter, final DatabaseMetaData metaData, final String catalogName, final String schemaName, final String tableName) throws SQLException { performResultSetXmlOperation(xmlWriter, null, new ResultSetXmlOperation() { public ResultSet getResultSet() throws SQLException { return metaData.getIndexInfo(catalogName, schemaName, tableName, false, false); } public void handleRow(PrettyPrintingXmlWriter xmlWriter, ResultSet result) throws SQLException { Set columns = getColumnsInResultSet(result); xmlWriter.writeElementStart(null, "index"); addStringAttribute(xmlWriter, "name", result, columns, "INDEX_NAME"); addBooleanAttribute(xmlWriter, "nonUnique", result, columns, "NON_UNIQUE"); addStringAttribute(xmlWriter, "indexCatalog", result, columns, "INDEX_QUALIFIER"); if (columns.contains("TYPE")) { try { switch (result.getShort("TYPE")) { case DatabaseMetaData.tableIndexStatistic: xmlWriter.writeAttribute(null, "type", "table statistics"); break; case DatabaseMetaData.tableIndexClustered: xmlWriter.writeAttribute(null, "type", "clustered"); break; case DatabaseMetaData.tableIndexHashed: xmlWriter.writeAttribute(null, "type", "hashed"); break; case DatabaseMetaData.tableIndexOther: xmlWriter.writeAttribute(null, "type", "other"); break; default: xmlWriter.writeAttribute(null, "type", "unknown"); break; } } catch (SQLException ex) { log("Could not read the TYPE value for an index of table '" + tableName + "' from the result set: " + ex.getStackTrace(), Project.MSG_ERR); } } addStringAttribute(xmlWriter, "column", result, columns, "COLUMN_NAME"); addShortAttribute(xmlWriter, "sequenceNumberInIndex", result, columns, "ORDINAL_POSITION"); if (columns.contains("ASC_OR_DESC")) { try { String value = result.getString("ASC_OR_DESC"); if ("A".equalsIgnoreCase(value)) { xmlWriter.writeAttribute(null, "sortOrder", "ascending"); } else if ("D".equalsIgnoreCase(value)) { xmlWriter.writeAttribute(null, "sortOrder", "descending"); } else { xmlWriter.writeAttribute(null, "sortOrder", "unknown"); } } catch (SQLException ex) { log("Could not read the ASC_OR_DESC value for an index of table '" + tableName + "' from the result set: " + ex.getStackTrace(), Project.MSG_ERR); } } addIntAttribute(xmlWriter, "cardinality", result, columns, "CARDINALITY"); addIntAttribute(xmlWriter, "pages", result, columns, "PAGES"); addStringAttribute(xmlWriter, "filter", result, columns, "FILTER_CONDITION"); } public void handleError(SQLException ex) { log("Could not read the indexes for table '" + tableName + "' from the result set: " + ex.getStackTrace(), Project.MSG_ERR); } }); }
From source file:org.executequery.databaseobjects.impl.TableColumnIndex.java
private String translateType(Short value) { String translated = String.valueOf(value); switch (value) { case DatabaseMetaData.tableIndexStatistic: return translated + " - tableIndexStatistic"; case DatabaseMetaData.tableIndexClustered: return translated + " - tableIndexClustered"; case DatabaseMetaData.tableIndexHashed: return translated + " - tableIndexHashed"; case DatabaseMetaData.tableIndexOther: return translated + " - tableIndexOther"; }//from w ww. j a v a2 s .com return translated; }