How to get JDBC Driver Name in Java?

Below code show how to get Driver name in java –

/****************************************************************************************
 * Created on 04-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: 4/30/11
 */
public class GetDriverName {
    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(meta.getDriverName());
    }
}

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.