How to get JDBC Driver Name in Java?

DeeKay April 30, 2011 at 10:46 pm · java.sql

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());
    }
}