Java JDBC Database Metadata getSchemas(Connection c)

Here you can find the source of getSchemas(Connection c)

Description

get Schemas

License

Apache License

Declaration

public static Map getSchemas(Connection c) throws SQLException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.sql.Connection;
import java.sql.DatabaseMetaData;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.util.HashMap;

import java.util.LinkedList;
import java.util.List;
import java.util.Map;

public class Main {
    public static Map getSchemas(Connection c) throws SQLException {
        DatabaseMetaData dmd = c.getMetaData();
        ResultSet rs = null;/*from   w  w w . j av  a 2  s. co  m*/
        try {
            rs = dmd.getSchemas();
            Map map = new HashMap();
            List l;
            while (rs.next()) {
                String schema = rs.getString(1);
                String catalog = null;
                if (rs.getMetaData().getColumnCount() > 1) {
                    catalog = rs.getString(2);
                }
                ;
                l = (List) map.get(catalog);
                if (l == null) {
                    l = new LinkedList();
                    map.put(catalog, l);
                }
                l.add(schema);
            }
            return map;
        } finally {
            if (rs != null)
                rs.close();
        }
    }
}

Related

  1. getPrimaryKeyColumn(DatabaseMetaData md, String TableName)
  2. getPrimaryKeyColumnNames(Connection connection, String tableName)
  3. getPrimaryKeys(Connection conn, String tableName)
  4. getQualifiedTableName(DatabaseMetaData dbmd, String catalog, String schema, String table, boolean useQuotes)
  5. getSchemaPattern(final DatabaseMetaData dbData, String schemaName)
  6. getSimplifiedURL(final DatabaseMetaData metadata)
  7. getTableColumns(Connection connection, String selectedTable)
  8. getTableMetadata(Connection connection, String tableName)
  9. getTableNames(Connection conn)