我编写了一个简单的代码来测试 oracle 驱动程序是否已经注册。
private boolean isDriverRegistered(){
boolean isRegistered = false;
Enumeration<Driver> loadedDrivers = DriverManager.getDrivers();
while(loadedDrivers.hasMoreElements()){
Driver driver = loadedDrivers.nextElement();
if (driver instanceof OracleDriver){
isRegistered = true;
break;
}
}
return isRegistered;
}
有人可以建议任何其他更好的方法吗?