DatabaseMetaData in JDBC

The DatabaseMetaData class is used to determine the capabilities of a JDBC driver and it database during runtime. If a given method of this interface is not supported by the JDBC driver, the method will either throw an SQLException, or in the case of a method that returns a result set, it may return null. Some of the methods take search patterns as its arguments. The pattern values used can be the SQL wildcard characters % and _. Other search arguments accept an empty set ("") when the argument is not applicable, or null to drop the argument from the search criteria.


  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.


Enter your email address to get our daily JOBS & INTERVIEW FAQ's Straight to your Inbox.

Make sure to activate your subscription by clicking on the activation link sent to your email