This interface is implemented by driver vendors to let users know the capabilities of a Database Management System (DBMS) in combination with the driver based on JDBC driver that is used with it. Different relational DBMSs often support different features, implement features in different ways, and use different data types. In addition, a driver may implement a feature on top of what the DBMS offers. Information returned by methods in this interface applies to the capabilities of a particular driver and a particular DBMS working together.
The JDBC API enables you to uncover metadata about a database using the DatabaseMetaData interfaces. The DatabaseMetaData interface enables you to obtain information about your database's attributes and make runtime decisions based around that information.
package com.javastuff.jdbc;
import java.sql.*;
import java.util.*;
import java.io.*;
public class DataBaseMetaDataExample {
public static void main(String s[]) throws Exception {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con =
DriverManager.getConnection("jdbc:odbc:javastuff", "scott","tiger");
DatabaseMetaData db= con.getMetaData();
System.out.println("Database name : "+db.getDatabaseProductName());
System.out.println("Database version : "+db.getDatabaseProductVersion());
System.out.println("\nDriver Name : "+ db.getDriverName());
System.out.println("Driver Version : "+ db.getDriverVersion());
con.close();
}//main
}//class
Note :To execute the following example you can replace username and password with your actual user name and password.
Posted in: