Java JDBC Driver getDriverFromPath(String path, String className)

Here you can find the source of getDriverFromPath(String path, String className)

Description

get Driver From Path

License

Open Source License

Declaration

public static Driver getDriverFromPath(String path, String className)
            throws ClassNotFoundException, InstantiationException, IllegalAccessException, MalformedURLException 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2006 Bruno G. Braga./*from  w  w w .j  av a  2 s  .com*/
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Bruno G. Braga - initial API and implementation
 *******************************************************************************/

import java.io.File;

import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;

import java.sql.Driver;

public class Main {
    public static Driver getDriverFromPath(String path, String className)
            throws ClassNotFoundException, InstantiationException, IllegalAccessException, MalformedURLException {
        URL[] url = { new File(path).toURL() };

        URLClassLoader loader = new URLClassLoader(url);

        Class c = loader.loadClass(className);
        Object instance = c.newInstance();

        return (Driver) instance;
    }
}

Related

  1. createDriver(String driverClassName)
  2. createDriver(String driverClassName)
  3. createDriver(String driverClassName)
  4. getDriverClassName(String rawUrl)
  5. getDriverClassName(String rawUrl)
  6. getRegisteredDrivers()
  7. getRSInfo(Object rsObj, int[] rsInfo, long[] rsCounter, Object[] conn, int[] errCode, String[] errDetail)
  8. getStatement()
  9. getUnderlyingDriver(String url)