Determine JDBC Driver Version

You may be required to determine the version of a JDBC driver used to connect to your Oracle Database. In cases were the JDBC driver used is the one included with Oracle Client or Database identification could be rather straight forward.

Many Oracle products that utilize JDBC connectivity store the JDBC driver used by the product in the ORACLE_PRODUCT_HOME/jdbc/lib directory and include a Readme.txt file that states the driver name. In some products this is not always the case.

Another problem in identifying the version is that the actual file name it self does not contain a hint about the driver version. For example the following show the JDBC drivers included with Oracle Enterprise Manager 11gR1 Grid Control Agent and Oracle Database Enterprise Edition 11gR2.

[oracle@prod jdbc]$ ls /u01/app/oracle/product/agent11g/jdbc/lib
ojdbc5dms_g.jar  ojdbc5dms.jar  ojdbc5_g.jar  ojdbc5.jar  ojdbc6dms_g.jar  ojdbc6dms.jar  ojdbc6_g.jar  ojdbc6.jar
[oracle@prod jdbc]$
[oracle@prod jdbc]$ ls /u01/app/oracle/product/11.2.0/dbhome_1/jdbc/lib
ojdbc5dms_g.jar  ojdbc5_g.jar  ojdbc6dms_g.jar  ojdbc6_g.jar  simplefan.jar
ojdbc5dms.jar    ojdbc5.jar    ojdbc6dms.jar    ojdbc6.jar
[oracle@prod jdbc]$ 

With the exception of the additional file simplefan.jar in the Database JDBC directory the file names are the same. It is only when we look at the Readme.txt file do we see that the JDBC drivers have different versions.

[oracle@prod jdbc]$ head  /u01/app/oracle/product/agent11g/jdbc/Readme.txt 
Oracle JDBC Drivers release - Production README

What Is New In This Release ?

Support for Java Standard Edition 6 (JSE6) and JDBC 4.0
    JSE 6 (AKA Mustang) is supported by the Thin and OCI drivers
    including support for the new JDBC spec, JDBC 4.0. The new 
[oracle@prod jdbc]$
[oracle@prod jdbc]$ head /u01/app/oracle/product/11.2.0/dbhome_1/jdbc/Readme.txt 
Oracle JDBC Drivers release production Readme.txt

What Is New In This Release ?

Universal Connection Pool
    In this release the Oracle Implicit Connection Cache feature is
    deprecated. Users are strongly encouraged to use the new Universal
[oracle@prod jdbc]$

While it might be expected that the drivers are different given each comes from a different 11g release of the specific product it could still lead to a source of confusion. And what if you are not aware of the difference in product releases?

Third party Software vendors are not obligated to adhere to a directory or file naming convention when using JDBC. This makes identifying the driver just by inspecting the file system difficult if not impossible.

Java provides an Interface called DatabaseMetaData that can be used to find a variety of information about the database. The Interface provides four methods that return information pertaining to the JDBC Driver used.

String getDriverName() // Retrieves the name of the JDBC Driver
String getDriverVersion() // Retrieves the version of the JDBC Driver
String getDriverMajorVersion() // Retrieves the JDBC Driver Major Version number
String getDriverMinorVersion() // Retrieved the JDBC Driver Minor Version number

Below is a simple Java class that makes a connection to a database and uses a DatabaseMetaData object to retrieve the JDBC Driver Name and version.

import oracle.jdbc.OracleConnection;
import oracle.jdbc.pool.OracleDataSource;
import java.sql.SQLException;
import java.sql.DatabaseMetaData;
import java.util.Properties;

public class JDBCVersionInfo {
  public static void main(String[] args) {
    try {
      // Set up user connection properties
      Properties prop = new Properties();
      // open the connection
      OracleDataSource ods = new OracleDataSource();
      OracleConnection ocon = (OracleConnection)ods.getConnection();
      DatabaseMetaData dbmd = ocon.getMetaData();
      System.out.println("Driver Name: " + dbmd.getDriverName());
      System.out.println("Driver Version: " + dbmd.getDriverVersion());
    } catch(SQLException e) {

If you are familiar with compiling and executing Java code feel free to skip the rest of the post. For those that are not familiar with compiling and executing Java code the steps below will help you to compile the and execute the Java code on your machine.

In order to run this you will need need the Java JDK installed on your system and the JAVA_HOME/bin directory should be in your path (example /opt/java/jdkx.x.x_xx/bin).

Copy the code above and save in a file called The name and case are important. Provide a user name and an password that are valid for your system in prop.setProperty lines 13 and 14.This code just makes a connection to the database no statements are executed.

Next on line 20 replace the prod:1521/proddb with the database server, port number and database name that are valid for your system.

After saving the changes we can now compile the program. Below is the command to compile the program. Change the path following the -cp to a path and JDBC driver on your system.

[oracle@prod code]$ javac -cp /u01/app/oracle/product/11.2.0/dbhome_1/jdbc/lib/ojdbc5.jar
[oracle@prod code]$ 
[oracle@prod code]$ ls
[oracle@prod code]$

Once the code have been compiled you will have two files with same name but different extensions. One will have the .java extension and the other will have the extension .class.

Next we run the compiled class file with command below. Note that the command to execute the class file is similar to the command to compile. Make sure you replace your path and file name in the command below. Also be sure to keep the trailing ;. .

[oracle@prod code]$ java -cp /u01/app/oracle/product/11.2.0/dbhome_1/jdbc/lib/ojdbc5.jar;. JDBCVersionInfo
Driver Name: Oracle JDBC driver
Driver Version:
[oracle@prod code]$ 

Here we see the version of the JDBC driver with no guesswork.

5 thoughts on “Determine JDBC Driver Version”

  1. Isn’t this way a bit faster?

    dmitry@winbox$ cd /cygdrive/c/app/oracle/product/11.2.0/client_1/jdbc/lib
    $ java -jar ojdbc6.jar
    Oracle JDBC 4.0 compiled with JDK6


  2. The java -jar trick does not work with ojbc14.jar. In that case, you need to use the code

  3. Thankyou for this article !
    I wondered if there is an version for Linux ..
    I will search ..

Leave a Reply

Your email address will not be published. Required fields are marked *