How Do You Find JDBC's Driver Information? JDBC

To find out a database’s vendor name and version information, you can invoke the following four methods from the DatabaseMetaData interface:

  • int getDatabaseMajorVersion(): Retrieves the major version number of the underlying database.(Note that in oracle.jdbc.OracleDatabaseMetaData, this method is not supported. Therefore, use a try-catch block in code. If the method returns a SQLException, we return the message “unsupported feature” in the XML result.)
  • int getDatabaseMinorVersion(): Retrieves the minor version number of the underlying database.
  • String getDatabaseProductName(): Retrieves the name of this database product.
  • String getDatabaseProductVersion(): Retrieves the version number of this database product.

Our solution combines these methods into a single method and returns the result as an XML String object, which any client can use. The result has the following syntax:

The Solution

The solution is generic and can support MySQL, Oracle, and other relational databases. Note that the getDatabaseMajorVersion() method (implemented by the oracle.jdbc.Oracle➥ DatabaseMetaData class) is an unsupported feature; therefore, we have to use a try-catch block. If the method returns a SQLException, we return the message “unsupported feature” in the XML result.

Client: Program for Getting Database Information

Running the Solution for a MySQL Database

Running the Solution for an Oracle Database

The following output is formatted to fit the page:

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd Protection Status

JDBC Topics