How does Squirrel add jdbc jars dynamically?

245 views Asked by At

Java Squirrel is an great sql tool. It supports ALL databases. I checked it. The only thing you need to do is to point to an external jar.

However, in java, a classpath is immutable. How is it possible? Here is the only solution that works How should I load Jars dynamically at runtime?. However the author says it's hackish

try {
    File file = ...
    URL url = file.toURI().toURL();

    URLClassLoader classLoader = (URLClassLoader)ClassLoader.getSystemClassLoader();
    Method method = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
    method.setAccessible(true);
    method.invoke(classLoader, url);
} catch (Exception ex) {
    ex.printStackTrace();
}  

How does Squirrel do it? I presume Squirrel is benchmark

0

There are 0 answers