use of com.varsql.core.exception.JdbcDriverClassException in project varsql by varsqlinfo.
the class JdbcDriverLoader method getJdbcDriver.
private Driver getJdbcDriver(JDBCDriverInfo jdbcDriverInfo) throws IOException, InstantiationException, IllegalAccessException, ClassNotFoundException {
List<FileInfo> jdbcList = jdbcDriverInfo.getDriverFiles();
if (jdbcList != null && jdbcList.size() > 0) {
List<URL> urlList = new ArrayList<>();
for (FileInfo item : jdbcList) {
Resource resource = ResourceUtils.getResource(item.getPath());
if (resource != null)
urlList.add(resource.getURL());
}
if (urlList.size() > 0) {
URLClassLoader ucl = new URLClassLoader(urlList.<URL>toArray(new URL[0]));
Class<?> driverClass = Class.forName(jdbcDriverInfo.getDriverClass(), true, ucl);
try {
return (Driver) driverClass.getDeclaredConstructor().newInstance();
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) {
throw new JdbcDriverClassException(e);
}
// return (Driver) Class.forName(jdbcDriverInfo.getDriverClass(), true, ucl).newInstance();
}
}
return null;
}
Aggregations