How to get JDBC Driver Major/Minor Version in Java?

Below code shows, how to get the Major and Minor version of JDBC driver in Java –

/****************************************************************************************
 * Created on 05-2011 Copyright(c) http://kodehelp.com All Rights Reserved.
 ****************************************************************************************/
package com.kodehelp.javasql;

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * Created by http://kodehelp.com
 * Date: 5/2/11
 */
public class GetMajorMinorVersion {
     public static void main(String[] args) throws SQLException, ClassNotFoundException {
        final String driver = "oracle.jdbc.driver.OracleDriver";
        final String url = "jdbc:oracle:thin:@HOST:PORT:SID";
        final String USERNAME = "USERNAME";
        final String PASSWORD = "PASSWORD";
        Class.forName(driver); // load Oracle driver
        Connection conn = DriverManager.getConnection(url, USERNAME, PASSWORD);
        DatabaseMetaData meta = conn.getMetaData();
        System.out.println("MAJOR VERSION ::"+meta.getDriverMajorVersion());
        System.out.println("MINOR VERSION ::"+meta.getDriverMinorVersion());
    }
}

Please Post Your Comments & Reviews

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.