Example usage for java.sql DriverManager getDrivers

List of usage examples for java.sql DriverManager getDrivers

Introduction

In this page you can find the example usage for java.sql DriverManager getDrivers.

Prototype

@CallerSensitive
public static Enumeration<Driver> getDrivers() 

Source Link

Document

Retrieves an Enumeration with all of the currently loaded JDBC drivers to which the current caller has access.

Usage

From source file:savant.sql.LoginDialog.java

/** Creates new form LoginDialog */
public LoginDialog(Window parent, SQLDataSourcePlugin plugin) {
    super(parent, ModalityType.APPLICATION_MODAL);
    initComponents();//from w ww  .j a  v a  2s .co m
    getRootPane().setDefaultButton(okButton);
    setLocationRelativeTo(parent);
    this.plugin = plugin;

    Enumeration<Driver> drivers = DriverManager.getDrivers();
    while (drivers.hasMoreElements()) {
        driverCombo.addItem(drivers.nextElement().getClass().getName());
    }

    driverCombo.setSelectedItem(plugin.driverName); // Driver name defaults to "com.mysql.jdbc.Driver" if not set.
    uriField.setText(plugin.uri.toString());
    userField.setText(plugin.userName);
    passwordField.setText(plugin.password);
}

From source file:com.p6spy.engine.spy.P6TestUtil.java

public static void printAllDrivers() {
    if (log.isDebugEnabled()) {
        for (Enumeration e = DriverManager.getDrivers(); e.hasMoreElements();) {
            log.debug("1 DRIVER FOUND == " + e.nextElement());
        }/*from   ww  w. j a va2  s.c  o m*/
    }
}

From source file:org.rhq.plugins.database.DatabasePluginLifecycleListener.java

public void shutdown() {
    // so we do not cause our classloader to leak perm gen, we need to de-register
    // any and all JDBC drivers this plugin registered
    Enumeration<Driver> drivers = DriverManager.getDrivers();
    while (drivers.hasMoreElements()) {
        try {// w  w  w  .ja  va2s  . c  o  m
            Driver driver = drivers.nextElement();
            DriverManager.deregisterDriver(driver);
            log.debug("Deregistered JDBC driver: " + driver.getClass());
        } catch (Exception e) {
            log.warn("Failed to deregister JDBC drivers - memory might leak" + ThrowableUtil.getAllMessages(e));
        }
    }

    log.debug(this.getClass().getSimpleName() + " completed shutdown.");
    return;
}

From source file:herddb.jdbc.CommonsDBCPTest.java

@After
public void destroy() throws Exception {
    for (Enumeration<java.sql.Driver> drivers = DriverManager.getDrivers(); drivers.hasMoreElements();) {
        DriverManager.deregisterDriver(drivers.nextElement());
    }// w w  w .jav a  2  s  .  com
}

From source file:com.evanmclean.evlib.commons.dbcp.DbcpUtils.java

/**
 * Get the DBCP pooling driver.//w w  w .java 2s  . co  m
 * 
 * @return Return the DBCP pooling driver or null.
 */
public static PoolingDriver getPoolingDriver() {
    PoolingDriver pdriver = null;
    final Enumeration<Driver> drivers = DriverManager.getDrivers();
    while (drivers.hasMoreElements()) {
        final Driver driver = drivers.nextElement();
        if (driver instanceof PoolingDriver) {
            if (pdriver == null)
                pdriver = (PoolingDriver) driver;
            else
                throw new IllegalStateException("More than one DBCP pooling driver.");
        }
    }
    return pdriver;
}

From source file:net.firejack.platform.model.config.listener.ConfigContextLoaderListener.java

@Override
public void contextDestroyed(ServletContextEvent event) {
    try {/*from ww  w . j  a v  a 2s. com*/
        Map<String, BasicDataSource> dataSources = getCurrentWebApplicationContext()
                .getBeansOfType(BasicDataSource.class);
        for (BasicDataSource dataSource : dataSources.values()) {
            try {
                dataSource.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }

        Enumeration<Driver> drivers = DriverManager.getDrivers();
        while (drivers.hasMoreElements()) {
            try {
                DriverManager.deregisterDriver(drivers.nextElement());
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }

        JAXBContextCache.clearCaches();
        ClassFactory.cleanCache();
        CachedIntrospectionResults.clearClassLoader(getClass().getClassLoader());
    } finally {
        super.contextDestroyed(event);
    }
}

From source file:com.parallax.server.blocklyprop.config.SetupConfig.java

@Override
public void contextDestroyed(ServletContextEvent servletContextEvent) {
    super.contextDestroyed(servletContextEvent);
    // This manually deregisters JDBC driver, which prevents Tomcat 7 from complaining about memory leaks wrto this class
    Enumeration<Driver> drivers = DriverManager.getDrivers();
    while (drivers.hasMoreElements()) {
        Driver driver = drivers.nextElement();
        try {//from w ww.  j  av  a  2  s.co m
            DriverManager.deregisterDriver(driver);
            //  LOG.log(Level.INFO, String.format("deregistering jdbc driver: %s", driver));
        } catch (SQLException sqlE) {
            //   LOG.log(Level.SEVERE, String.format("Error deregistering driver %s", driver), e);
        }

    }
}

From source file:nl.strohalm.cyclos.setup.DataBaseConfiguration.java

public void release() {
    if (driverToUnregister != null) {
        Enumeration<Driver> drivers = DriverManager.getDrivers();
        while (drivers.hasMoreElements()) {
            Driver driver = drivers.nextElement();
            if (driverToUnregister.isInstance(driver)) {
                try {
                    DriverManager.deregisterDriver(driver);
                } catch (Exception e) {
                    // Ignore
                }/*from   w  ww. ja v  a2  s. com*/
            }
        }
    }
}

From source file:org.glite.security.voms.admin.persistence.HibernateFactory.java

protected static void unregisterSQLDrivers() {

    Enumeration<Driver> drivers = DriverManager.getDrivers();

    while (drivers.hasMoreElements()) {
        Driver driver = drivers.nextElement();
        try {/*ww  w . j av a2 s  .c o m*/

            DriverManager.deregisterDriver(driver);

        } catch (SQLException e) {
            log.warn("Error deregistering driver {}", driver, e);
        }

    }

}

From source file:de.anycook.db.mysql.DBHandler.java

public static void closeSource() {
    try {/*ww  w  . j  a v a  2s.com*/
        dataSource.close();
        dataSource = null;
        Enumeration<Driver> drivers = DriverManager.getDrivers();
        while (drivers.hasMoreElements()) {
            DriverManager.deregisterDriver(drivers.nextElement());
        }
    } catch (SQLException e) {
        sLogger.error(e);
    }
}