Java JDBC Database Metadata getTableNames(DatabaseMetaData dbMD)

Here you can find the source of getTableNames(DatabaseMetaData dbMD)

Description

get Table Names

License

Open Source License

Declaration

public static List getTableNames(DatabaseMetaData dbMD) throws SQLException 

Method Source Code


//package com.java2s;
/*/*from w ww  .  j  ava2 s . c  o m*/
 * JBoss, Home of Professional Open Source.
 * Copyright 2006, Red Hat Middleware LLC, and individual contributors
 * as indicated by the @author tags. See the copyright.txt file in the
 * distribution for a full listing of individual contributors.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.DatabaseMetaData;
import java.sql.Connection;

import java.util.List;
import java.util.ArrayList;

public class Main {
    private static final String TABLE_NAME = "TABLE_NAME";

    public static List getTableNames(DatabaseMetaData dbMD) throws SQLException {
        ResultSet rs = dbMD.getTables(null, null, null, null);
        List results = new ArrayList();
        while (rs.next()) {
            results.add(rs.getString(TABLE_NAME));
        }
        safeClose(rs);
        return results;
    }

    public static void safeClose(Connection con) {
        if (con != null)
            try {
                con.close();
            } catch (Exception e) {
            }
    }

    public static void safeClose(ResultSet rs) {
        if (rs != null)
            try {
                rs.close();
            } catch (Exception e) {
            }
    }
}

Related

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