Java JDBC Driver createDriver(String driverClassName)

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

Description

create Driver

License

Open Source License

Declaration

public static Driver createDriver(String driverClassName) throws SQLException 

Method Source Code

//package com.java2s;

import java.sql.Driver;

import java.sql.SQLException;

public class Main {
    public static Driver createDriver(String driverClassName) throws SQLException {
        try {/*from  ww  w  .  j a  va2  s .  com*/
            return (Driver) Class.forName(driverClassName).newInstance();
        } catch (IllegalAccessException e) {
            throw new SQLException(e.getMessage(), e);
        } catch (InstantiationException e) {
            throw new SQLException(e.getMessage(), e);
        } catch (ClassNotFoundException e) {
            // skip
        }

        try {
            return (Driver) Thread.currentThread().getContextClassLoader().loadClass(driverClassName).newInstance();
        } catch (IllegalAccessException e) {
            throw new SQLException(e.getMessage(), e);
        } catch (InstantiationException e) {
            throw new SQLException(e.getMessage(), e);
        } catch (ClassNotFoundException 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)