Java SQL Table getTableNames(Connection conn)

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

Description

get Table Names

License

LGPL

Declaration

static public List getTableNames(Connection conn) throws SQLException 

Method Source Code


//package com.java2s;
//License from project: LGPL 

import java.sql.Connection;
import java.sql.DatabaseMetaData;

import java.sql.ResultSet;
import java.sql.SQLException;

import java.util.ArrayList;
import java.util.Collections;

import java.util.List;

public class Main {
    static public List getTableNames(Connection conn) throws SQLException {
        DatabaseMetaData dbmd = conn.getMetaData();
        String[] types = new String[] { "TABLE", "VIEW" };
        ResultSet rs = dbmd.getTables(null, null, null, types);
        List tables = null;/*from  w w  w  . java  2  s .c o m*/
        while (rs.next()) {
            String tableName = rs.getString("TABLE_NAME");
            if (tables == null) {
                tables = new ArrayList();
            }
            tables.add(tableName);
        }
        if (tables != null) {
            Collections.sort(tables);
        }
        return tables;
    }
}

Related

  1. getShapeText(Connection conn, String tableName)
  2. getTableFields(Connection con, String tableName)
  3. getTableList(Connection connection)
  4. getTableName(String sql)
  5. getTableNames(Connection conn)
  6. getTables(Connection conn)
  7. getTables(Connection connection)
  8. getTables(Connection connection)
  9. getTables(Connection connection)