JDBC DatabaseMetaData


Prev Tutorial Next Tutorial

DatabaseMetaData in JDBC

This metadata interface is used for reading metadata about a database.

Metadata about database is nothing but reading database server, version, driver name and its version, maximum number of columns allowed in a table etc.

How to get the object of DatabaseMetaData

To obtain a object of DatabaseMetaData, we need to call getMetaData() method of Connection object.

Syntax

DatabaseMetaData dbms=con.getMetaData();

Methods of DatabaseMetaData

The methods to read some metadata information are:

methodDiscription
1getDatabaseProductName()To read database server name.
2getDatabaseProductVersion()To read database server version.
3getDriverName()To read driver software name.
4getColumnInTable()To find maximum number of columns allowed in the table..

Example of DatabaseMetaData

import java.sql.*;
class DBMetaDeta
{
public static void main(String[] args) throws Exception
{
Class.forName("oracle.jdbc.OracleDriver");
Connection con=DriverManager.getConnection("jdbc:oracle:thin:@rama-pc:1521:xe","system","system");
System.out.println("conection is opened");
Statement stmt=con.createStatement();
DatabaseMetaData dbmd=con.getMetaData();
System.out.println("database server name:"+dbmd.getDatabaseProductName());
System.out.println("database server version:"+dbmd.getDatabaseProductVersion());
System.out.println("driver server version:"+dbmd.getDriverVersion());
System.out.println("driver server name:"+dbmd.getDriverName());
System.out.println("max columns:"+dbmd.getMaxColumnsInTable());
stmt.close();
con.close();
}
}

Prev Tutorial Next Tutorial

Advertisements




Facebook Likes

Advertisements