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.


DatabaseMetaData dbms=con.getMetaData();

Methods of DatabaseMetaData

The methods to read some metadata information are:

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
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());

Prev Tutorial Next Tutorial

Download Projects

Google Adsense Advertisements
Free Classified Site – Bedpage

Yahoo Advertisements