Java JDBC Database Metadata getDBTables(DatabaseMetaData metaData, String dataBase, String user)

Here you can find the source of getDBTables(DatabaseMetaData metaData, String dataBase, String user)

Description

get DB Tables

License

Apache License

Parameter

Parameter Description
metaData DatabaseMetaData
dataBase String
user String

Exception

Parameter Description
SQLException an exception

Return

String[]

Declaration

public static String[] getDBTables(DatabaseMetaData metaData, String dataBase, String user)
        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 {
    /**/*  w w  w .  j av  a 2 s.c  o  m*/
     * 
     * 
     * @param conn     Connection
     * @param user     String
     * @param dataBase String
     * @return String[]
     * @throws SQLException
     */
    public static String[] getDBTables(Connection conn, String user, String dataBase) throws SQLException {
        return getDBTables(conn.getMetaData(), dataBase, user);
    }

    /**
     * 
     * 
     * @param metaData DatabaseMetaData
     * @param dataBase String
     * @param user     String
     * @return String[]
     * @throws SQLException
     */
    public static String[] getDBTables(DatabaseMetaData metaData, String dataBase, String user)
            throws SQLException {
        ResultSet rs = metaData.getTables(dataBase, null, user, new String[] { "TABLE" });
        List<String> tables = new ArrayList<String>();
        try {
            while (rs.next()) {
                tables.add(rs.getString("TABLE_NAME"));
            }
        } finally {
            rs.close();
        }
        String result[] = new String[tables.size()];
        tables.toArray(result);
        return result;
    }
}

Related

  1. getDatabaseInfo(Connection connection_)
  2. getDatabaseMetaData(Connection con)
  3. getDatabaseType(DatabaseMetaData metaData)
  4. getDBMSName(Connection conn)
  5. getDBProduct(Connection conn)
  6. getDbType(Connection connection)
  7. getDBUsers(DatabaseMetaData metaData)
  8. getDriverSpecificSettings(Connection connection, String defaultUnionColumnValue)
  9. getForeignKeyDeferrability(int code)