DriverManager and ClassLoader
843854Jun 2 2004 — edited Aug 19 2004Hi,
I've got a stand-alone IDE type application that creates a "project classloader". This classloader contains the users classes, as well as any JDBC driver JARs that their system needs. I can load their classes just fine with the project classloader, and I can also load the JDBC driver using it. When I then go to get a Connection via
DriverManager.getConnection(url,props);
This keeps throwing
java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getConnection(DriverManager.java:532)
at java.sql.DriverManager.getConnection(DriverManager.java:140)
Clearly DriverManager is being loaded in the System ClassLoader whilst the JDBC driver is in the project ClassLoader and hence the problem.
What solutions are there ?
1. I don't want to impose on the user to put all JDBC JARs in the CLASSPATH, but is there some way I can add them dynamically in a reliable way ?
2. Any way to get DriverManager and the loaded JDBC driver to register themselves correctly ?
3. Other ideas ?
I'm using JDK 1.4.2 on Linux.
TIA