I have java app that loads the database driver jar file into the classpath with the following code
for (int i = 0; i < fileNames.length; i++)
{
Method method = (URLClassLoader.class).getDeclaredMethod("addURL", new Class[] {URL.class});
method.setAccessible(true);
method.invoke((URLClassLoader)ClassLoader.getSystemClassLoader(), new Object[] { new File(fileNames[i]).toURI().toURL() });
}
Class.forName(driverClassName);
con = DriverManager.getConnection(_url, _uid, _pwd);
This does not work with Java 9 because it gets a cast exception when casting system class loader to URLClassLoader. How can you to do this in java 9?
Here is new code
String[] fileNames = m_dbDriverFileName.split(";");
URL[] path = new URL[fileNames.length];
for (int i = 0; i < fileNames.length; i++)
{
path[i] = new File(fileNames[i]).toURI().toURL();
}
URLClassLoader child = new URLClassLoader(path, this.getClass().getClassLoader());
Class.forName(m_dbDriverClass, true, child);