当前位置: 首页>>代码示例>>Java>>正文


Java DriverManager.getDrivers方法代码示例

本文整理汇总了Java中java.sql.DriverManager.getDrivers方法的典型用法代码示例。如果您正苦于以下问题:Java DriverManager.getDrivers方法的具体用法?Java DriverManager.getDrivers怎么用?Java DriverManager.getDrivers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.sql.DriverManager的用法示例。


在下文中一共展示了DriverManager.getDrivers方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: beforeJFinalStop

import java.sql.DriverManager; //导入方法依赖的package包/类
@Override
public void beforeJFinalStop() {
    Enumeration<Driver> drivers = DriverManager.getDrivers();
    if (drivers != null) {
        while (drivers.hasMoreElements()) {
            try {
                Driver driver = drivers.nextElement();
                DriverManager.deregisterDriver(driver);
            } catch (Exception e) {
                log.error(e.toString(), e);
            }
        }
    }
    JbootConfigManager.me().destroy();
    JbootAppListenerManager.me().onJFinalStop();
}
 
开发者ID:yangfuhai,项目名称:jboot,代码行数:17,代码来源:JbootAppConfig.java

示例2: deregisterJdbcDrivers

import java.sql.DriverManager; //导入方法依赖的package包/类
private void deregisterJdbcDrivers() {
  ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
  Enumeration<Driver> drivers = DriverManager.getDrivers();

  while (drivers.hasMoreElements()) {
    LOGGER.debug("Deregistering JDBC Drivers:");
    Driver driver = drivers.nextElement();
    if (driver.getClass().getClassLoader() == classLoader) {
      try {
        LOGGER.debug("  {} v{}.{}",
            driver.getClass().getName(),
            driver.getMajorVersion(),
            driver.getMinorVersion()
        );

        DriverManager.deregisterDriver(driver);
      } catch (SQLException e) {
        LOGGER.error("Failed to deregister JDBC driver: ", e);
      }
    }
  }
}
 
开发者ID:durimkryeziu,项目名称:jersey-2.x-webapp-for-servlet-container,代码行数:23,代码来源:SampleApplicationDestroyListener.java

示例3: clearJdbcDriverRegistrations

import java.sql.DriverManager; //导入方法依赖的package包/类
public List<String> clearJdbcDriverRegistrations() throws SQLException {
    List<String> driverNames = new ArrayList<String>();

    /*
     * DriverManager.getDrivers() has a nasty side-effect of registering
     * drivers that are visible to this class loader but haven't yet been
     * loaded. Therefore, the first call to this method a) gets the list
     * of originally loaded drivers and b) triggers the unwanted
     * side-effect. The second call gets the complete list of drivers
     * ensuring that both original drivers and any loaded as a result of the
     * side-effects are all de-registered.
     */
    HashSet<Driver> originalDrivers = new HashSet<Driver>();
    Enumeration<Driver> drivers = DriverManager.getDrivers();
    while (drivers.hasMoreElements()) {
        originalDrivers.add(drivers.nextElement());
    }
    drivers = DriverManager.getDrivers();
    while (drivers.hasMoreElements()) {
        Driver driver = drivers.nextElement();
        // Only unload the drivers this web app loaded
        if (driver.getClass().getClassLoader() !=
            this.getClass().getClassLoader()) {
            continue;
        }
        // Only report drivers that were originally registered. Skip any
        // that were registered as a side-effect of this code.
        if (originalDrivers.contains(driver)) {
            driverNames.add(driver.getClass().getCanonicalName());
        }
        DriverManager.deregisterDriver(driver);
    }
    return driverNames;
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:35,代码来源:JdbcLeakPrevention.java

示例4: registeredDrivers

import java.sql.DriverManager; //导入方法依赖的package包/类
private List<Driver> registeredDrivers() {
  List<Driver> result = new ArrayList<>();
  for (Enumeration<Driver> driverEnumeration = DriverManager.getDrivers();
      driverEnumeration.hasMoreElements(); ) {
    result.add(driverEnumeration.nextElement());
  }
  return result;
}
 
开发者ID:opentracing-contrib,项目名称:java-jdbc,代码行数:9,代码来源:TracingDriver.java

示例5: removeAllDrivers

import java.sql.DriverManager; //导入方法依赖的package包/类
/**
 * Utility method to remove all registered drivers
 */
private static void removeAllDrivers() {
    java.util.Enumeration e = DriverManager.getDrivers();
    while (e.hasMoreElements()) {
        try {
            DriverManager.deregisterDriver((Driver) (e.nextElement()));
        } catch (SQLException ex) {
            System.out.print(ex.getMessage());
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:14,代码来源:DriverManagerTests.java

示例6: isDriverRegistered

import java.sql.DriverManager; //导入方法依赖的package包/类
/**
 * Utility method to see if a driver is registered
 */
private boolean isDriverRegistered(Driver d) {
    boolean foundDriver = false;
    java.util.Enumeration e = DriverManager.getDrivers();
    while (e.hasMoreElements()) {
        if (d == (Driver) e.nextElement()) {
            foundDriver = true;
            break;
        }
    }
    return foundDriver;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:15,代码来源:DriverManagerTests.java

示例7: clearJdbcDriverRegistrations

import java.sql.DriverManager; //导入方法依赖的package包/类
public List<String> clearJdbcDriverRegistrations() throws SQLException {
	List<String> driverNames = new ArrayList<String>();

	/*
	 * DriverManager.getDrivers() has a nasty side-effect of registering
	 * drivers that are visible to this class loader but haven't yet been
	 * loaded. Therefore, the first call to this method a) gets the list of
	 * originally loaded drivers and b) triggers the unwanted side-effect.
	 * The second call gets the complete list of drivers ensuring that both
	 * original drivers and any loaded as a result of the side-effects are
	 * all de-registered.
	 */
	HashSet<Driver> originalDrivers = new HashSet<Driver>();
	Enumeration<Driver> drivers = DriverManager.getDrivers();
	while (drivers.hasMoreElements()) {
		originalDrivers.add(drivers.nextElement());
	}
	drivers = DriverManager.getDrivers();
	while (drivers.hasMoreElements()) {
		Driver driver = drivers.nextElement();
		// Only unload the drivers this web app loaded
		if (driver.getClass().getClassLoader() != this.getClass().getClassLoader()) {
			continue;
		}
		// Only report drivers that were originally registered. Skip any
		// that were registered as a side-effect of this code.
		if (originalDrivers.contains(driver)) {
			driverNames.add(driver.getClass().getCanonicalName());
		}
		DriverManager.deregisterDriver(driver);
	}
	return driverNames;
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:34,代码来源:JdbcLeakPrevention.java

示例8: getAllDrivers

import java.sql.DriverManager; //导入方法依赖的package包/类
private static Enumeration<Driver> getAllDrivers() {
    return DriverManager.getDrivers();
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:4,代码来源:DatabaseService.java

示例9: injectDriverManager

import java.sql.DriverManager; //导入方法依赖的package包/类
/**
 * inject DriverManager
 * 
 * @param webapploader
 * @param appid
 * @return
 */
private void injectDriverManager(ClassLoader webapploader, InterceptContext ic) {

    if (isHookEventDone("isInjectDrvMgr")) {
        return;
    }

    JdbcDriverIT jdbcDriverIT = new JdbcDriverIT(this.getAppID(ic));

    jdbcDriverIT.initSomeDrivers(webapploader);

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

    while (eu.hasMoreElements()) {

        Driver dr = eu.nextElement();

        jdbcDriverIT.doRegisterDriver(dr, true);
    }

}
 
开发者ID:uavorg,项目名称:uavstack,代码行数:28,代码来源:JdbcHookProxy.java


注:本文中的java.sql.DriverManager.getDrivers方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。