我想从给定的模式名称中检索所有表,但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中检索所有表。现在它显示了本地数据库中存在的所有模式的结果。
你可以使用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)
}