Java JDBC Driver createDriver(String driverClassName)

Here you can find the source of createDriver(String driverClassName)

Description

create Driver

License

Apache License

Declaration

public static Driver createDriver(String driverClassName) throws SQLException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.sql.Driver;

import java.sql.SQLException;

public class Main {
    public static Driver createDriver(String driverClassName) throws SQLException {
        Class clazz = null;//ww w .j  a v  a 2  s  .  c  om
        try {
            ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
            if (contextLoader != null) {
                clazz = contextLoader.loadClass(driverClassName);
            }
        } catch (ClassNotFoundException e) {
        }
        if (clazz == null) {
            try {
                clazz = Class.forName(driverClassName);
            } catch (ClassNotFoundException e) {
                throw new SQLException(e.getMessage(), e);
            }
        }
        try {
            return (Driver) clazz.newInstance();
        } catch (IllegalAccessException e) {
            throw new SQLException(e.getMessage(), e);
        } catch (InstantiationException e) {
            throw new SQLException(e.getMessage(), e);
        }
    }
}

Related

  1. createDriver(ClassLoader classLoader, String driverClassName)
  2. createDriver(String driverClassName)
  3. createDriver(String driverClassName)
  4. getDriverClassName(String rawUrl)
  5. getDriverClassName(String rawUrl)
  6. getDriverFromPath(String path, String className)
  7. getRegisteredDrivers()