Example: Returning a list of tables using the DatabaseMetaData interface

This example shows how to return a list of tables.

Note: By using the code examples, you agree to the terms of the Code license and disclaimer information.
// Connect to the server.
Connection c = DriverManager.getConnection("jdbc:db2:mySystem");
 
// Get the database meta data from the connection.
DatabaseMetaData dbMeta = c.getMetaData();
 
// Get a list of tables matching this criteria.           
String catalog = "myCatalog";
String schema = "mySchema";
String table  = "myTable%"; // % indicates search pattern
String types[] = {"TABLE", "VIEW", "SYSTEM TABLE"}:
ResultSet rs = dbMeta.getTables(catalog, schema, table, types);
 
// ... iterate through the ResultSet to get the values.
 
// Close the connection.
c.close():