本文整理汇总了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();
}
示例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;
}
示例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;
}
示例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());
}
}
}
示例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;
}
示例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;
}
示例8: getAllDrivers
import java.sql.DriverManager; //导入方法依赖的package包/类
private static Enumeration<Driver> getAllDrivers() {
return DriverManager.getDrivers();
}
示例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);
}
}