What Is the JDBC View of a Database's Internal Structure? in JDBC

The JDBC views a database in terms of catalog, schema, table, view, column, triggers, indexes, and stored procedures. The JDBC view of a database’s internal structure appears in Figure

Internal structure of a database

From the JDBC view of a database:

  • A database server has several catalogs (such as database partitions and databases).
  • A catalog has several schemas (these are user-specific namespaces).
  • A schema has several database objects (tables, views, triggers, indexes, stored procedures,etc.).

The java.sql.DatabaseMetaData interface has methods for discovering all the catalogs, schemas, tables, views, indexes, and stored procedures in the database server. These methods return a ResultSet, which can be traversed for getting the desired information.

public static void main(String[] args) throws Exception {
// Load the database driver - in this case, we
// use the Jdbc/Odbc bridge driver.
Connection conn = null;
try {
// Open a connection to the database
conn = DriverManager.getConnection(
"[jdbcURL]", "[login]", "[passwd]");
// Get DatabaseMetaData
DatabaseMetaData dbmd = conn.getMetaData();
// Get all Catalogs
System.out.println("\nCatalogs are called '" + dbmd.getCatalogTerm()
+ "' in this RDBMS.");
processResultSet(dbmd.getCatalogTerm(), dbmd.getCatalogs());
Figure 3-3. Internal structure of a database
// Get all Schemas
System.out.println("\nSchemas are called '" + dbmd.getSchemaTerm()
+ "' in this RDBMS.");
processResultSet(dbmd.getSchemaTerm(), dbmd.getSchemas());
// Get all Table-like types
System.out.println("\nAll table types supported in this RDBMS:");
processResultSet("Table type", dbmd.getTableTypes());
finally {
// Close the Connection object
public static void processResultSet(String preamble, ResultSet rs)
throws SQLException {
// Printout table data
while(rs.next()) {
// Printout
System.out.println(preamble + ": " + rs.getString(1));
// Close database resources

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

JDBC Topics