Java Code Examples for java.sql.DriverManager#deregisterDriver()

The following examples show how to use java.sql.DriverManager#deregisterDriver() . 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: BaseTest.java    From phoenix with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
protected static synchronized boolean destroyDriver() {
    if (driver != null) {
        driverRefCount--;
        if (driverRefCount == 0) {
            try {
                try {
                    driver.close();
                    return true;
                } finally {
                    try {
                        DriverManager.deregisterDriver(driver);
                    } finally {
                        driver = null;
                    }
                }
            } catch (SQLException e) {
            }
        }
    }
    return false;
}
 
Example 2
Source File: SimpleHiveConnManager.java    From bigdata-tutorial with Apache License 2.0 6 votes vote down vote up
/**
 * 关闭所有连接,撤销驱动程序的注册
 */
public synchronized void release() {
	// 等待直到最后一个客户程序调用
	if (--clients != 0) {
		return;
	}
	Enumeration allPools = pools.elements();
	while (allPools.hasMoreElements()) {
		ConnPool pool = (ConnPool) allPools.nextElement();
		pool.release();
	}
	Enumeration allDrivers = drivers.elements();
	while (allDrivers.hasMoreElements()) {
		Driver driver = (Driver) allDrivers.nextElement();
		try {
			DriverManager.deregisterDriver(driver);
			log("撤销JDBC驱动程序 " + driver.getClass().getName() + "的注册");
		} catch (SQLException e) {
			log(e, "无法撤销下列JDBC驱动程序的注册: " + driver.getClass().getName());
		}
	}
}
 
Example 3
Source File: DriversDeregister.java    From cosmo with Apache License 2.0 6 votes vote down vote up
@Override
public void onApplicationEvent(ContextClosedEvent event) {

    LOG.info("[Drivers] About to de-register drivers...");
    Enumeration<Driver> drivers = DriverManager.getDrivers();
    while (drivers.hasMoreElements()) {
        Driver driver = drivers.nextElement();
        LOG.info("[Drivers] De-registering {}", driver);
        try {
            DriverManager.deregisterDriver(driver);
        } catch (SQLException e) {
            LOG.error("Failed to deregister driver: {}", driver.getClass());
        }
    }
    LOG.info("[Drivers] De-registered drivers.");
}
 
Example 4
Source File: JdbcConnectionSourceTest.java    From ormlite-jdbc with ISC License 6 votes vote down vote up
@Test
public void testClose() throws Exception {
	Connection conn = createMock(Connection.class);
	conn.setAutoCommit(true);
	conn.close();
	Driver driver = createMock(Driver.class);
	String url = "jdbc:bar:baz";
	expect(driver.acceptsURL(url)).andReturn(true);
	expect(driver.connect(isA(String.class), isA(Properties.class))).andReturn(conn);
	replay(driver, conn);
	DriverManager.registerDriver(driver);
	try {
		JdbcConnectionSource sds = new JdbcConnectionSource(url, databaseType);
		assertNotNull(sds.getReadOnlyConnection(null));
		sds.close();
		verify(driver, conn);
	} finally {
		DriverManager.deregisterDriver(driver);
	}
}
 
Example 5
Source File: AbstractITest.java    From ClickHouse-Native-JDBC with Apache License 2.0 6 votes vote down vote up
protected void withNewConnection(WithConnection withConnection, Object... args)
    throws Exception {
    // deregisterDriver other jdbc drivers
    Enumeration<Driver> drivers = DriverManager.getDrivers();
    while (drivers.hasMoreElements()) {
        DriverManager.deregisterDriver(drivers.nextElement());
    }
    DriverManager.registerDriver(new ClickHouseDriver());

    String connectionStr = "jdbc:clickhouse://127.0.0.1:" + SERVER_PORT;

    // first arg is use_client_time_zone
    if (args.length > 0) {
        if (args[0].equals(true)) {
            connectionStr += "?use_client_time_zone=true";
        }
    }
    Connection connection = DriverManager.getConnection(connectionStr);
    try {
        withConnection.apply(connection);
    } finally {
        connection.close();
    }
}
 
Example 6
Source File: DriverManagerTests.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Register a driver and make sure you find it via its URL. Deregister the
 * driver and validate it is not longer registered
 *
 * @throws Exception
 */
@Test()
public void test15() throws Exception {
    DriverManager.registerDriver(new StubDriver());
    Driver d = DriverManager.getDriver(StubDriverURL);
    assertTrue(d != null);
    assertTrue(isDriverRegistered(d));
    DriverManager.deregisterDriver(d);
    assertFalse(isDriverRegistered(d));
}
 
Example 7
Source File: TestUtils.java    From pentaho-aggdesigner with GNU General Public License v2.0 5 votes vote down vote up
public static void deregisterDriver(final String jdbcDriverClasspath, final String jdbcDriverClassname)
    throws Exception {
  Driver registeredDriver = registeredDrivers.get(jdbcDriverClasspath + ":" + jdbcDriverClassname); //$NON-NLS-1$
  if (null != registeredDriver) {
    DriverManager.deregisterDriver(registeredDriver);
  }
}
 
Example 8
Source File: ConnectionParamITest.java    From ClickHouse-Native-JDBC with Apache License 2.0 5 votes vote down vote up
@Before
public void init() throws SQLException {
    Enumeration<Driver> drivers = DriverManager.getDrivers();
    while (drivers.hasMoreElements()) {
        DriverManager.deregisterDriver(drivers.nextElement());
    }
    DriverManager.registerDriver(new ClickHouseDriver());
}
 
Example 9
Source File: JobUtil.java    From spark-llap with Apache License 2.0 5 votes vote down vote up
public static void replaceSparkHiveDriver() throws Exception {
  Enumeration<Driver> drivers = DriverManager.getDrivers();
  while(drivers.hasMoreElements()) {
    Driver driver = drivers.nextElement();
    String driverName = driver.getClass().getName();
    LOG.debug("Found a registered JDBC driver {}", driverName);
    if(driverName.endsWith("HiveDriver")) {
      LOG.debug("Deregistering {}", driverName);
      DriverManager.deregisterDriver(driver);
    } else {
      LOG.debug("Not deregistering the {}", driverName);
    }
  }
  DriverManager.registerDriver((Driver) Class.forName("shadehive.org.apache.hive.jdbc.HiveDriver").newInstance());
}
 
Example 10
Source File: DBImpl.java    From olat with Apache License 2.0 5 votes vote down vote up
@Override
public void destroy() {
    // clean up registered drivers to prevent messages like
    // The web application [/olat] registered the JBDC driver [org.hsqldb.jdbc.JDBCDriver] but failed to unregister...
    final Enumeration<Driver> registeredDrivers = DriverManager.getDrivers();
    while (registeredDrivers.hasMoreElements()) {
        try {
            DriverManager.deregisterDriver(registeredDrivers.nextElement());
        } catch (final SQLException e) {
            log.error("Could not unregister database driver.", e);
        }
    }
}
 
Example 11
Source File: GemFireXDDataExtractorImpl.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/*** Connection and Driver Methods ***/
private void stopServer() throws SQLException, Exception {
  try {
    if (this.jdbcConn != null) {
      this.jdbcConn.close();
    }

    DriverManager.deregisterDriver(driver);
    final FabricService fs = FabricServiceManager.getFabricServerInstance();

    if (fs != null) {
      fs.stop(new Properties());
    }

    final GemFireCacheImpl cache = GemFireCacheImpl.getInstance();
    DistributedSystem ds = null;

    if (cache != null) {
      ds = cache.getDistributedSystem();
      if (ds != null) {
        ds.disconnect();
      }
    }
  } catch (Exception e) {
    logSevere("Unable to stop the server ", e , reportableErrors);
  }
  GFXDDiskStoreImpl.cleanUpOffline();
}
 
Example 12
Source File: DriverManagerTests.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Validate that DriverAction.release is called when a driver is registered
 * via registerDriver(Driver, DriverAction)
 *
 * @throws Exception
 */
@Test
public void test16() throws Exception {
    File file = new File(util.StubDriverDA.DriverActionCalled);
    file.delete();
    assertFalse(file.exists());
    Driver d = null;
    Class.forName("util.StubDriverDA");
    d = DriverManager.getDriver(StubDriverDAURL);
    DriverManager.deregisterDriver(d);
    assertFalse(isDriverRegistered(d), "Driver is registered");
    assertTrue(file.exists());
}
 
Example 13
Source File: DriverManagerTests.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Validate that a null value allows for deRegisterDriver to return
 */
@Test
public void test3() throws Exception {
    DriverManager.deregisterDriver(null);

}
 
Example 14
Source File: DriverManagerTests.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Validate that a null value allows for deRegisterDriver to return
 */
@Test
public void test3() throws Exception {
    DriverManager.deregisterDriver(null);

}
 
Example 15
Source File: DriverManagerPermissionsTests.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions = AccessControlException.class)
public void test7() throws SQLException {
    setPolicy(new TestPolicy());
    DriverManager.deregisterDriver(new StubDriver());
}
 
Example 16
Source File: DriverManagerPermissionsTests.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test9() throws SQLException {
    setPolicy(new TestPolicy("all"));
    DriverManager.deregisterDriver(new StubDriver());
}
 
Example 17
Source File: DriverManagerTests.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Validate that a null value allows for deRegisterDriver to return
 */
@Test
public void test3() throws Exception {
    DriverManager.deregisterDriver(null);

}
 
Example 18
Source File: DriverManagerPermissionsTests.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test9() throws SQLException {
    setPolicy(new TestPolicy("all"));
    DriverManager.deregisterDriver(new StubDriver());
}
 
Example 19
Source File: DriverManagerPermissionsTests.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions = AccessControlException.class)
public void test7() throws SQLException {
    setPolicy(new TestPolicy());
    DriverManager.deregisterDriver(new StubDriver());
}
 
Example 20
Source File: DriverManagerPermissionsTests.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test9() throws SQLException {
    setPolicy(new TestPolicy("all"));
    DriverManager.deregisterDriver(new StubDriver());
}