DatabaseMetaData dmd = conn.getMetaData();
ResultSet res = dmd.getTables(conn.getCatalog(), null,null,new String[] {"TABLE"});
System.out.println("List of tables: ");
while (res.next()) {
System.out.println(
" "+res.getString("TABLE_CAT")
+ ", "+res.getString("TABLE_SCHEM")
+ ", "+res.getString("TABLE_NAME")
+ ", "+res.getString("TABLE_TYPE")
+ ", "+res.getString("REMARKS"));
}
返回结果:
List of tables:
Northwind, dbo, Categories, TABLE, null
Northwind, dbo, CustomerCustomerDemo, TABLE, null
Northwind, dbo, CustomerDemographics, TABLE, null
Northwind, dbo, Customers, TABLE, null
Northwind, dbo, Employees, TABLE, null
Northwind, dbo, EmployeeTerritories, TABLE, null
Northwind, dbo, Order Details, TABLE, null
Northwind, dbo, Orders, TABLE, null
Northwind, dbo, Products, TABLE, null
Northwind, dbo, Region, TABLE, null
Northwind, dbo, Shippers, TABLE, null
Northwind, dbo, Suppliers, TABLE, null
Northwind, dbo, Territories, TABLE, null
本文详细介绍了如何使用 Java 编程语言通过 JDBC 接口获取数据库元数据,并以 Northwind 数据库为例展示了如何遍历并打印所有表的详细信息。
3227

被折叠的 条评论
为什么被折叠?



