What is DatabaseMetaData?

It is used to get comprensive(meta) information about database.
Connection interface returns the object of DataBaseMetaData interface.
Methods are like
getDatabaseProductName()
getDatabaseProductVersion()
getDriverName()
getDriverVersion()
Example:
import java.sql.*;
class demo
{
public static void main(String[] args){
Connection con=null;
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","system","oracle");
DatabaseMetaData dmd=con.getMetaData();
System.out.println("database name:"+dmd.getDatabaseProductName());
System.out.println("database version:"+dmd.getDatabaseProductVersion());
System.out.println("driver name:"+dmd.getDriverName());
System.out.println("driver version:"+dmd.getDriverVersion());
}catch(Exception e){
System.out.println("the exception is::::->"+e);
}
finally{
try{
con.close();}
catch(Exception e){
System.out.println("2nd try block exception:::->"+e);
}}}};

No comments:

Post a Comment