import java.sql.*; import oracle.jdbc.OracleDatabaseMetaData; public class DatabaseMetaDataSample { static final String dbURI = "jdbc:oracle:thin:@::"; public static void main(String args[]) throws Exception {
// Connection reference Connection conn = null;
try {
// Load database driver DriverManager.registerDriver (new oracle.jdbc.OracleDriver());
// Make connection conn = DriverManager.getConnection(dbURI,"<username>","<password>");
// Get the database meta data OracleDatabaseMetaData dmd = (OracleDatabaseMetaData)conn.getMetaData();
if (dmd == null) { System.out.println("Database meta data not available"); } else {
// Dispay Database Produce Name System.out.println("Database Product Name :" + dmd.getDatabaseProductName());
// Dispay Database Produce Version System.out.println("Database Product Version :" + dmd.getDatabaseProductVersion());
// Dispay Maximum Lenght of Table Name System.out.println("Maximum Table Name length :" + dmd.getMaxTableNameLength());
// Dispay precision for LOB System.out.println("LOB Precision :" + dmd.getLobPrecision());
// Dispay if the database uses local files if (dmd.usesLocalFiles()) System.out.println("The Database uses Local Files"); else System.out.println("The Database does not use Local Files");
System.out.println("The following Schemas are available in the database:"); ResultSet rs = dmd.getSchemas(); ResultSet rs1 = null; while(rs.next()) { System.out.println(rs.getString(1)); System.out.println( "The following tables are available in the "+rs.getString(1)+" schema:"); rs1 = dmd.getTables(null,rs.getString(1),"%",null); while(rs1.next()) { System.out.println(" "+ rs1.getString(3)+" :"+rs1.getString(4)); } } } } finally {
// Close connection if (conn != null) { try { conn.close(); } catch (SQLException ex) { System.out.println("Error in closing Conection"); } } } } }