Bom dia amigos,
Eu gostaria de saber como faço para pegar o nome de todas as tabelas de um banco, eu tentei usar o getTables da classe DatabaseMetaData, mas não entendi os parâmetros que ele pede e ele me retorna um resultset e não o nomes de todas as tabelas existentes no banco. Alguém pode me indicar uma forma de conseguir essa informação?
Desde Já agradeço
Logan
thingol
Dezembro 6, 2006, 11:10am
#2
Uai, mas o ResultSet contém os nomes das tabelas, conforme solicitado
E o Google ainda continua seu amigo. Dê uma olhada em:
http://publib.boulder.ibm.com/infocenter/iadthelp/v6r0/index.jsp?topic=/com.ibm.etools.iseries.toolbox.doc/jdbcdbmd.htm
javadoc:
public ResultSet getTables(String catalog,
String schemaPattern,
String tableNamePattern,
String[] types)
throws SQLException
Retrieves a description of the tables available in the given catalog. Only table descriptions matching the catalog, schema, table name and type criteria are returned. They are ordered by TABLE_TYPE, TABLE_SCHEM and TABLE_NAME.
Each table description has the following columns:
1. TABLE_CAT String => table catalog (may be null)
2. TABLE_SCHEM String => table schema (may be null)
3. TABLE_NAME String => table name
4. TABLE_TYPE String => table type. Typical types are "TABLE", "VIEW", "SYSTEM TABLE", "GLOBAL TEMPORARY", "LOCAL TEMPORARY", "ALIAS", "SYNONYM".
5. REMARKS String => explanatory comment on the table
6. TYPE_CAT String => the types catalog (may be null)
7. TYPE_SCHEM String => the types schema (may be null)
8. TYPE_NAME String => type name (may be null)
9. SELF_REFERENCING_COL_NAME String => name of the designated "identifier" column of a typed table (may be null)
10. REF_GENERATION String => specifies how values in SELF_REFERENCING_COL_NAME are created. Values are "SYSTEM", "USER", "DERIVED". (may be null)
Note: Some databases may not return information for all tables.
Parameters:
catalog - a catalog name; must match the catalog name as it is stored in the database; "" retrieves those without a catalog; null means that the catalog name should not be used to narrow the search
schemaPattern - a schema name pattern; must match the schema name as it is stored in the database; "" retrieves those without a schema; null means that the schema name should not be used to narrow the search
tableNamePattern - a table name pattern; must match the table name as it is stored in the database
types - a list of table types to include; null returns all types
Returns:
ResultSet - each row is a table description
Throws:
SQLException - if a database access error occurs
See Also:
getSearchStringEscape()
Mantu
Dezembro 6, 2006, 12:06pm
#3
Não serviria utilizar, a partir do objeto ResultSet , o método [color=blue]getMetaData() [/color], que retorna um objeto [color=blue]ResultSetMetaData() [/color]?
Amigos,
Eujá havia encontrado a descrição do método na dacumentação do java, contudo eu não entendi esses parâmentros que teriamque passar eu montei assim
con = DriverManager.getConnection(url, usuario, senha);
System.out.println("Conectou");
rs = con.getMetaData().getTables(null, null, "", null);
e nada é retornado tentei fazer um rs.next mas ele me retorna false, tenho certeza que estou usando parametros incorretos na chamada do método, só não sei quais seriam certos
oyama
Dezembro 6, 2006, 4:33pm
#5
Qual o banco de dados que voce esta usando?
Em Oracle, eu não conheço o conceito de catalog, mas existe o conceito de schema. Acho que um dos dois voce teria que passar, dependendo do banco de dados. Quanto ao pattern eu não tenho a minima ideia se é para usar regexp, padrão do banco de dados, ou outro padrão. Acho que depende do driver JDBC.
eu trabalho tanto com o Mysql como com o Access, na verdade nunca ouvi falar em catalog, e esquema só quando vc acessa o banco via runtime do netBeans