1

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

Community
  • 1
  • 1
john
  • 647
  • 5
  • 23
  • 53
  • The link doesn't seem to work http://git.code.sf.net/p/squirrel-sql/git squirrel-sql-git – john Dec 25 '16 at 12:32
  • try here: https://sourceforge.net/p/squirrel-sql/git/ci/master/tree/ – Andy Guibert Dec 25 '16 at 21:43
  • but in general, adding jars at runtime is not "hackish" -- this is one of the core principals of OSGi. The code snippet you showed above is a bit hacky, although it could be more cleanly done by creating a new URLClassLoader with a parent of the system CL (which does not require relfection and therefore is not "hacky") – Andy Guibert Dec 25 '16 at 21:44

0 Answers0