getTables方法不接受schema参数并返回所有模式中的表

问题描述 投票:0回答:1

我想从给定的模式名称中检索所有表,但getTables方法不接受任何参数(模式等),并返回整个数据库中的所有表。

我试过使用getTables但是没有像我预期的那样工作。

private void countTables() throws IllegalAccessException, SQLException, InstantiationException, ClassNotFoundException, IOException {
        Set tables = getTables();
        for (Iterator iterator = tables.iterator(); iterator.hasNext();) {
            String tableName = (String) iterator.next();
            int rowCount = getRowCount(tableName);
            getWriter().write(tableName + "=[" + rowCount + "]\r\n");
        }
        getWriter().flush();
        getWriter().close();
    }

我想从架构test1中检索所有表。现在它显示了本地数据库中存在的所有模式的结果。

java sql
1个回答
0
投票

你可以使用DatabaseMetaData

Connection con = db.getConnection();
    DatabaseMetaData metaData = con.getMetaData();

    String tableType[] = {"TABLE"};    

   ResultSet result = metaData.getTables(null,SCHEMA_NAME,null,tableType);
 while(result.next())
    {
     String tableName = result.getString(3);
     System.out.println(tableName)
}
© www.soinside.com 2019 - 2024. All rights reserved.