Java JDBC Database Metadata getTableNames(Connection conn)

Here you can find the source of getTableNames(Connection conn)

Description

get Table Names

License

Open Source License

Declaration

public static Set<String> getTableNames(Connection conn) throws SQLException 

Method Source Code

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

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

import java.sql.ResultSet;

import java.sql.SQLException;

import java.util.LinkedHashSet;
import java.util.Set;

public class Main {
    public static Set<String> getTableNames(Connection conn) throws SQLException {
        DatabaseMetaData dbmd = conn.getMetaData();
        return getTableNames(conn, dbmd.getUserName());
    }//  ww  w  .  j  a v  a  2 s  .c  o  m

    public static Set<String> getTableNames(Connection conn, String schemaPattern) throws SQLException {
        DatabaseMetaData dbmd = conn.getMetaData();

        Set<String> result = new LinkedHashSet<String>();
        ResultSet rs = dbmd.getTables("", schemaPattern, "*", null);
        try {
            while (rs.next()) {
                result.add(rs.getString(3));
            }
        } finally {
            rs.close();
        }

        return result;
    }
}

Related

  1. getSchemaPattern(final DatabaseMetaData dbData, String schemaName)
  2. getSchemas(Connection c)
  3. getSimplifiedURL(final DatabaseMetaData metadata)
  4. getTableColumns(Connection connection, String selectedTable)
  5. getTableMetadata(Connection connection, String tableName)
  6. getTableNames(DatabaseMetaData dbMD)
  7. isDB2(DatabaseMetaData metadata)
  8. isDerbyDatabase(DatabaseMetaData metaData)
  9. isExistsTable(Connection con, String schema, String tableName)