Java Code Examples for java.sql.DriverManager#getDrivers()
The following examples show how to use
java.sql.DriverManager#getDrivers() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EntityManagerContainerFactory.java From o2oa with GNU Affero General Public License v3.0 | 6 votes |
public static void close() throws Exception { try { if (instance != null) { for (EntityManagerFactory emf : instance.entityManagerFactoryMap.values()) { if (emf.isOpen()) { emf.close(); } } instance.entityManagerFactoryMap.clear(); instance.checkPersistFieldMap.clear(); instance.checkRemoveFieldMap.clear(); } /* 注销驱动程序 */ Enumeration<Driver> drivers = DriverManager.getDrivers(); while (drivers.hasMoreElements()) { Driver driver = drivers.nextElement(); DriverManager.deregisterDriver(driver); } /* 由于可能重新载入 */ instance = null; } catch (Exception e) { throw new Exception("close error.", e); } }
Example 2
Source File: AutoloadTest.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * Return true if there appears to be a Derby embedded * driver registered with the DriverManager. * @return true if there appears to be a Derby embedded driver registered */ private boolean isEmbeddedDriverRegistered() { for (Enumeration e = DriverManager.getDrivers(); e.hasMoreElements(); ) { Driver d = (Driver) e.nextElement(); String driverClass = d.getClass().getName(); if (!driverClass.startsWith("com.pivotal.gemfirexd.internal.")) continue; if (driverClass.equals("com.pivotal.gemfirexd.jdbc.ClientDriver")) continue; // Some form of Derby embedded driver seems to be registered. return true; } return false; }
Example 3
Source File: RhnServletListener.java From spacewalk with GNU General Public License v2.0 | 5 votes |
/** {@inheritDoc} */ public void contextDestroyed(ServletContextEvent sce) { stopMessaging(); logStop("Messaging"); stopHibernate(); logStop("Hibernate"); if (sce == null) { // this has been called from the testsuite, next steps would // break subsequent tests return; } // This manually deregisters JDBC driver, // which prevents Tomcat from complaining about memory leaks Enumeration<Driver> drivers = DriverManager.getDrivers(); while (drivers.hasMoreElements()) { Driver driver = drivers.nextElement(); try { DriverManager.deregisterDriver(driver); log.info("deregistering jdbc driver: " + driver); } catch (SQLException e) { log.warn("Error deregistering driver " + driver); } } // shutdown the logger to avoid ThreadDeath exception during // webapp reload. LogManager.shutdown(); }
Example 4
Source File: JdbcLeakPrevention.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
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; }
Example 5
Source File: DriverManagerTests.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
/** * 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; }
Example 6
Source File: DriverManagerTests.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
/** * 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; }
Example 7
Source File: YHttpServlet.java From yawl with GNU Lesser General Public License v3.0 | 5 votes |
private void deregisterDbDrivers() { Enumeration<Driver> drivers = DriverManager.getDrivers(); while (drivers.hasMoreElements()) { Driver driver = drivers.nextElement(); try { DriverManager.deregisterDriver(driver); _log.info("Deregistered JDBC driver: {}", driver); } catch (SQLException e) { _log.warn("Unable to deregister JDBC driver {}: {}", driver, e.getMessage()); } } }
Example 8
Source File: UtilHelpers.java From hudi with Apache License 2.0 | 5 votes |
/** * Returns a factory for creating connections to the given JDBC URL. * * @param options - JDBC options that contains url, table and other information. * @return * @throws SQLException if the driver could not open a JDBC connection. */ private static Connection createConnectionFactory(Map<String, String> options) throws SQLException { String driverClass = options.get(JDBCOptions.JDBC_DRIVER_CLASS()); DriverRegistry.register(driverClass); Enumeration<Driver> drivers = DriverManager.getDrivers(); Driver driver = null; while (drivers.hasMoreElements()) { Driver d = drivers.nextElement(); if (d instanceof DriverWrapper) { if (((DriverWrapper) d).wrapped().getClass().getCanonicalName().equals(driverClass)) { driver = d; } } else if (d.getClass().getCanonicalName().equals(driverClass)) { driver = d; } if (driver != null) { break; } } Objects.requireNonNull(driver, String.format("Did not find registered driver with class %s", driverClass)); Properties properties = new Properties(); properties.putAll(options); Connection connect; String url = options.get(JDBCOptions.JDBC_URL()); connect = driver.connect(url, properties); Objects.requireNonNull(connect, String.format("The driver could not open a JDBC connection. Check the URL: %s", url)); return connect; }
Example 9
Source File: JdbcLeakPrevention.java From Tomcat8-Source-Read with MIT License | 5 votes |
public List<String> clearJdbcDriverRegistrations() throws SQLException { List<String> driverNames = new ArrayList<>(); /* * 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<>(); 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; }
Example 10
Source File: DriverManagerTests.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
/** * 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; }
Example 11
Source File: DriverManagerTests.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * 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; }
Example 12
Source File: MetaDataTest.java From quark with Apache License 2.0 | 5 votes |
@Test public void testDriverRegistered() throws SQLException { Enumeration<Driver> drivers = DriverManager.getDrivers(); List<Driver> driverList = Collections.list(drivers); List<String> driverNames = new ArrayList<>(); for (Driver driver : driverList) { driverNames.add(driver.getClass().getCanonicalName()); log.debug("Found driver: " + driver.getClass().getCanonicalName()); } assertThat(driverNames).contains("com.qubole.quark.fatjdbc.QuarkDriver"); }
Example 13
Source File: DriverManagerTests.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
/** * 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; }
Example 14
Source File: DriverManagerTests.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
/** * 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()); } } }
Example 15
Source File: SpannerServiceContributorTest.java From google-cloud-spanner-hibernate with GNU Lesser General Public License v2.1 | 5 votes |
private void deregisterDrivers() { try { Enumeration<Driver> drivers = DriverManager.getDrivers(); while (drivers.hasMoreElements()) { DriverManager.deregisterDriver(drivers.nextElement()); } } catch (SQLException exc) { throw new NestedApplicationException(exc); } }
Example 16
Source File: RelvarJDBCMetadata.java From Rel with Apache License 2.0 | 5 votes |
private static String obtainDriverList() { String list = ""; Enumeration<Driver> drivers = DriverManager.getDrivers(); while (drivers.hasMoreElements()) { Driver driver = drivers.nextElement(); if (!list.isEmpty()) list += ", "; list += driver.getClass().getName(); } return (list.isEmpty()) ? "<none>" : list; }
Example 17
Source File: JdbcHookProxy.java From uavstack with Apache License 2.0 | 4 votes |
/** * 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); } }
Example 18
Source File: JdbcDriverZookeeperTest.java From herddb with Apache License 2.0 | 4 votes |
@AfterClass public static void destroy() throws Exception { for (Enumeration<java.sql.Driver> drivers = DriverManager.getDrivers(); drivers.hasMoreElements(); ) { DriverManager.deregisterDriver(drivers.nextElement()); } }
Example 19
Source File: BxDriverManager.java From beakerx with Apache License 2.0 | 4 votes |
public static java.util.Enumeration<Driver> getDrivers() { return DriverManager.getDrivers(); }
Example 20
Source File: AuthTest.java From herddb with Apache License 2.0 | 4 votes |
@After public void destroy() throws Exception { for (Enumeration<java.sql.Driver> drivers = DriverManager.getDrivers(); drivers.hasMoreElements(); ) { DriverManager.deregisterDriver(drivers.nextElement()); } }