What Is an Example of JDBC Metadata Programming? JDBC

Suppose you want to get the major and minor JDBC version number for the driver you are using. You can use the following methods from DatabaseMetaData:

As you can see, these methods do not return the employee or inventory data, but they return metadata. Our solution combines these 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 is generic and can support MySQL, Oracle, and other relational databases. If Connection.getMetaData() returns null, then it means that vendor's driver does not support implement thejava.sql.DatabaseMetaData interface. Note that the getDatabase MajorVersion() method (implemented by the oracle.jdbc.OracleDatabaseMetaData 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:

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 DMCA.com Protection Status

JDBC Topics