Java JDBC Database Metadata getDBUsers(DatabaseMetaData metaData)

Here you can find the source of getDBUsers(DatabaseMetaData metaData)

Description

get DB Users

License

Apache License

Declaration

public static String[] getDBUsers(DatabaseMetaData metaData) 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.ArrayList;

import java.util.List;

public class Main {

    public static String[] getDBUsers(Connection conn) throws SQLException {
        return getDBUsers(conn.getMetaData());
    }/*w ww .  ja  v a2 s .  c om*/

    public static String[] getDBUsers(DatabaseMetaData metaData) throws SQLException {
        ResultSet rs = metaData.getSchemas();
        List<String> users = new ArrayList<String>();
        try {
            while (rs.next()) {
                users.add(rs.getString("TABLE_SCHEM"));
            }
        } finally {
            rs.close();
        }
        String result[] = new String[users.size()];
        users.toArray(result);
        return result;
    }
}

Related

  1. getDatabaseType(DatabaseMetaData metaData)
  2. getDBMSName(Connection conn)
  3. getDBProduct(Connection conn)
  4. getDBTables(DatabaseMetaData metaData, String dataBase, String user)
  5. getDbType(Connection connection)
  6. getDriverSpecificSettings(Connection connection, String defaultUnionColumnValue)
  7. getForeignKeyDeferrability(int code)
  8. getJDBCMajorVersion(Connection conn)
  9. getNullableDescription(int type)