VOOZH about

URL: https://www.geeksforgeeks.org/java/how-to-extract-database-metadata-using-jdbc/

⇱ Retrieving Database Metadata Using JDBC - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Retrieving Database Metadata Using JDBC

Last Updated : 24 Apr, 2026

DatabaseMetaData is an interface in Java Programming, and it is part of JDBC also. DatabaseMetaData is an interface in JDBC used to obtain information about the database, including its structure, properties, and supported features.

  • Retrieves details like database name, version, and driver information.
  • Provides information about tables, columns, primary keys, and foreign keys.
  • Helps determine supported SQL syntax and database capabilities.

We can obtain metadata from the connection object:

DatabaseMetaData metaData = con.getMetaData();

Programs to Extract Database Metadata using JDBC

In this example, first connect to the database using configuration details like host, database name, username, password, and port. Then, we create a DatabaseMetaData object using con.getMetaData() and use it to retrieve database information.

  • Database product name and version
  • Driver name and version
  • Connection and user information
  • Database URL details
  • Supported date and time functions

1. Database Product Name

Retrieve the database product name using the DatabaseMetaData object. It provides the getDatabaseProductName() method to access this information.

Implementation:

Output:

Below we can refer the output in console.

👁 Database Product Name Output

2. Database Product Version

By using DatabaseMetaDase we get the information about data. Here, we get the information like database product version by using getDatabaseProductVersion() from DatabaseMetaDase. We get the current version of database.

Output:

Below we can refer the output in console.

👁 Database Product Version Output

3. Driver Name

Get the database driver name using the DatabaseMetaData interface. It provides the getDriverName() method to retrieve and display the driver information.

Output: Below we can refer the output in console.

👁 Driver Name Output

4. Driver Version

Retrieve the database driver version using the DatabaseMetaData interface. It provides the getDriverVersion() method to get and display the driver version information.

Implementation

Output:

Below we can refer the output in console.

👁 Driver Version Output

5. Database Connection Information

Retrieve database connection details using the DatabaseMetaData interface. The getConnection() method helps access the connection object and related information like the JDBC driver.

Output:

Below we can refer the output in console.

👁 Database Connection Information Output

6. Database Username Information

Retrieve the database username using the DatabaseMetaData interface. The getUserName() method returns the name of the current database user.

Implementation

Output:

Below we can refer the output in console.

👁 Database Username Information Output

7. Database URL information

Retrieve the database URL using the DatabaseMetaData interface. The getURL() method provides details like host name, database name, and port number.

Output:

Below we can refer the output in console.

👁 Database URL information Output

8. Database Time Date functions information

Retrieve supported time and date functions using the DatabaseMetaData interface. The getDateTimeFunctions() method returns the list of available functions.

Output:

Below we can refer the output in console.

👁 Database Time Date functions information Output
Comment
Article Tags:
Article Tags: