All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.rapidark.preloader.JdbcLeakPrevention Maven / Gradle / Ivy

The newest version!
package com.github.rapidark.preloader;

import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.List;

public class JdbcLeakPrevention {
	public List clearJdbcDriverRegistrations() throws SQLException {
		List driverNames = new ArrayList();

		HashSet originalDrivers = new HashSet();
		Enumeration drivers = DriverManager.getDrivers();
		while (drivers.hasMoreElements()) {
			originalDrivers.add((Driver) drivers.nextElement());
		}
		drivers = DriverManager.getDrivers();
		while (drivers.hasMoreElements()) {
			Driver driver = (Driver) drivers.nextElement();
			if (driver.getClass().getClassLoader() == getClass().getClassLoader()) {
				if (originalDrivers.contains(driver)) {
					driverNames.add(driver.getClass().getCanonicalName());
				}
				DriverManager.deregisterDriver(driver);
			}
		}
		return driverNames;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy