Java SQL Table getTablesFromDatabase(Connection conn)

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

Description

get Tables From Database

License

Open Source License

Declaration

public static List<String> getTablesFromDatabase(Connection conn) 

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.ArrayList;
import java.util.List;

public class Main {
    public static List<String> getTablesFromDatabase(Connection conn) {
        List<String> tables = new ArrayList<>();
        String types[] = new String[] { "TABLE", "VIEW" };

        DatabaseMetaData md;//w ww.ja  va  2 s  .com
        try {
            md = conn.getMetaData();
            ResultSet rs = md.getTables(null, null, "%", types);
            while (rs.next()) {
                String tn = rs.getString(3);
                tables.add(tn);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }

        return tables;
    }
}

Related

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