Java SQL Table getAllTableNames(Connection connection)

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

Description

Returns a list of all table names in the database schema accessible by the given connection.

License

Open Source License

Parameter

Parameter Description
connection connection

Exception

Parameter Description

Return

list of table names

Declaration

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

Method Source Code

//package com.java2s;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import java.util.List;

public class Main {
    /**/*w w  w.j av a2 s.c  om*/
     * Returns a list of all table names in the database schema accessible by
     * the given connection.
     *
     * @param connection connection
     * @return list of table names
     * @throws java.sql.SQLException if connection fails or meta-data could not be retrieved
     */
    public static List<String> getAllTableNames(Connection connection)
            throws SQLException {
        List<String> tables = new ArrayList<String>();

        ResultSet rs = connection.getMetaData().getTables(null, null, null,
                null);
        while (rs.next())
            tables.add(rs.getString(3));
        rs.close();

        return tables;
    }
}

Related

  1. dropTable(String tableName, Connection con)
  2. dumpTable(Connection conn, String TableName, PrintWriter out)
  3. dumpTable(Connection connection, String tablename)
  4. dumpTableToFile(Connection con, String table, String fileName)
  5. exportTableData(String tableName, Connection con)
  6. getAllTables(Connection conn)
  7. getBatchResultMessage(String tableName, int rowIdx, int resultCode)
  8. getCount(Connection conn, String tableName)
  9. getIdNumber(String tableName)