Java SQL Table getTables(Connection connection)

Here you can find the source of getTables(Connection connection)

Description

Retrieves all tables from the database currently connected to and store them in an ArrayList of Strings.

License

Open Source License

Exception

Parameter Description
SQLException an exception

Declaration

public static List<String> getTables(Connection connection) throws SQLException 

Method Source Code

//package com.java2s;
/**//from   ww w. ja  v  a 2 s  .  c o m
 * Candybean is a next generation automation and testing framework suite.
 * It is a collection of components that foster test automation, execution
 * configuration, data abstraction, results illustration, tag-based execution,
 * top-down and bottom-up batches, mobile variants, test translation across
 * languages, plain-language testing, and web service testing.
 * Copyright (C) 2013 SugarCRM, Inc. <candybean@sugarcrm.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

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 {
    /**
     * Retrieves all tables from the database currently connected to and store them in an ArrayList of Strings.
     * 
     * @author Jason Lin (ylin)
     * 
     * @return
     * @throws SQLException
     */
    public static List<String> getTables(Connection connection) throws SQLException {
        DatabaseMetaData dbmd = connection.getMetaData();
        List<String> tables = new ArrayList<String>();
        String[] types = { "TABLE" };
        ResultSet resultSet = dbmd.getTables(null, null, "%", types);
        while (resultSet.next()) {
            String tableName = resultSet.getString("TABLE_NAME");
            tables.add(tableName);
        }
        resultSet.close();
        return tables;
    }
}

Related

  1. getTableNames(Connection conn)
  2. getTableNames(Connection conn)
  3. getTables(Connection conn)
  4. getTables(Connection connection)
  5. getTables(Connection connection)
  6. getTablesFromDatabase(Connection conn)
  7. getTableSize(Connection conn, String tableName)
  8. getTableSize(final Statement statement, final String schema, final String table, boolean scope)
  9. getTotalRows(String tableName, Statement statement)