JDBC DatabaseMetaData

Advertisements

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

Google Advertisment

Buy This Ad Space @$20 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 9999595223

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

For Projects 9999595223

Google Advertisements


Buy Websites 9999595223

Buy College Projects with Documentation Contact on whatsapp 9999595223. Contact on: hitesh.xc@gmail.com or 9999595223 Try this Keyword C++ Programs

Advertisements