Java JDBC Driver loadDriver(String driver)

Here you can find the source of loadDriver(String driver)

Description

load the driver, if 'driver' is null then uses DEFAULT_DRIVER

License

Open Source License

Parameter

Parameter Description

Return

Class, the class loaded with Class.forName

Declaration

public static Class loadDriver(String driver) throws SQLException 

Method Source Code

//package com.java2s;
/** Copyright (C) (MSA, Inc) All rights reserved.
 ** General Public License: http://www.opensource.org/licenses/gpl-license.php
 **//* w w  w .j av  a  2s  .  c  om*/

import java.sql.*;

public class Main {
    /**
     * Holds the default JDBC driver.
     * Value is "sun.jdbc.odbc.JdbcOdbcDriver".
     */
    public static final String DEFAULT_DRIVER = "sun.jdbc.odbc.JdbcOdbcDriver";

    /** load the driver, if 'driver' is null then uses DEFAULT_DRIVER
     ** @param driver, String
     ** @return Class, the class loaded with Class.forName
     **/
    public static Class loadDriver(String driver) throws SQLException {
        try {
            if (driver == null)
                driver = DEFAULT_DRIVER;
            System.out.println("........loading:" + driver);
            Class drCl = Class.forName(driver);
            return drCl;
        } catch (IllegalArgumentException iae) {
            throw new SQLException("Driver class (" + driver + "): possibly wrong format: " + iae.getMessage());
        } catch (ClassNotFoundException e) {
            throw new SQLException("Could not find database driver class:" + driver);
        }
    }
}

Related

  1. getRSInfo(Object rsObj, int[] rsInfo, long[] rsCounter, Object[] conn, int[] errCode, String[] errDetail)
  2. getStatement()
  3. getUnderlyingDriver(String url)
  4. hasDriver()
  5. isDriverLoaded(String driver)
  6. loadDriver(String driverClassName, String jarFileName)
  7. printAllDrivers()