InterviewSolution
| 1. |
How Can I Investigate The Physical Structure Of A Database? |
|
Answer» The JDBC view of a database internal structure can be seen in the image below.
The DatabaseMetaData interface has methods for discovering all the Catalogs, Schemas, Tables and Stored Procedures in the database server. The methods are pretty intuitive, returning a ResultSet with a single String column; use them as indicated in the code below: public STATIC void main(String[] args) throws Exception{ // LOAD the database driver - in this CASE, we // use the Jdbc/Odbc bridge driver. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); // Open a connection to the database Connection 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()); // 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()); // Close the Connection conn.close(); } 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 rs.close(); } The JDBC view of a database internal structure can be seen in the image below. The DatabaseMetaData interface has methods for discovering all the Catalogs, Schemas, Tables and Stored Procedures in the database server. The methods are pretty intuitive, returning a ResultSet with a single String column; use them as indicated in the code below: |
|