Java JDBC Driver isDriverLoaded(String driver)

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

Description

Check if the database driver is loaded.

License

Open Source License

Return

True if the driver is loaded, False otherwise.

Declaration

public static boolean isDriverLoaded(String driver) 

Method Source Code


//package com.java2s;
/*//from www  .ja  va 2s.c  om
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
    
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
    
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    
Copyright (C) 2007 Marco Aurelio Graciotto Silva <magsilva@gmail.com>
*/

import java.sql.Driver;
import java.sql.DriverManager;

import java.util.Enumeration;

public class Main {
    /**
     * Check if the database driver is loaded.
     * 
     * @return True if the driver is loaded, False otherwise.
     */
    public static boolean isDriverLoaded(String driver) {
        // Check if the driver has been already loaded
        Enumeration<Driver> drivers = DriverManager.getDrivers();
        while (drivers.hasMoreElements()) {
            Driver d = drivers.nextElement();
            if (d.getClass().getName().equals(driver)) {
                return true;
            }
        }
        return false;
    }
}

Related

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