Java JDBC MySQL Connection getMysqlIndices(String conString)

Here you can find the source of getMysqlIndices(String conString)

Description

get Mysql Indices

License

Open Source License

Declaration

public static HashMap<String, HashSet<String>> getMysqlIndices(String conString) throws SQLException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.sql.*;
import java.util.*;

public class Main {
    public static HashMap<String, HashSet<String>> getMysqlIndices(String conString) throws SQLException {
        HashMap<String, HashSet<String>> result = new HashMap<String, HashSet<String>>();

        Connection conn;//from   w  w  w  . ja  va 2s  .c  om

        conn = DriverManager.getConnection(conString);
        DatabaseMetaData meta = conn.getMetaData();
        ResultSet tables = meta.getTables(null, null, null, null);
        while (tables.next()) {
            ResultSet rs;
            String tableName = tables.getString(3);
            rs = meta.getPrimaryKeys(null, null, tableName);
            HashSet<String> hash = new HashSet<String>();
            result.put(tableName.toLowerCase(), hash);
            while (rs.next()) {
                hash.add(rs.getString("COLUMN_NAME"));
                // String columnName = rs.getString("COLUMN_NAME");
                // System.out.println(tables.getString(3));
                // System.out.println("getPrimaryKeys(): columnName=" +
                // columnName);
            }
            rs.close();

        }
        tables.close();
        conn.close();
        return result;
    }
}

Related

  1. getMysqlConnection(final String url)
  2. getMySQLConnection(Properties props)
  3. getMySQLConnection(String cloudSqlInstance, String dbName, String userName, String password)
  4. getMySQLConnection(String hostname, String databaseName, String dbuser, String dbpasswort)
  5. getMySQLConnection(String hostName, String dbName, String userName, String password)
  6. getNewDatabaseConnection(String dbUser, String dbPassword)
  7. getRssminerDB()
  8. getSearchReaderConnection()
  9. openConnection()