I need to test a JDBC connection to a database. The java code to do that should be as simple as:
DriverManager.getConnection(\"jdbc connection URL\", \"usern
The problem is DriverManager
performs "tasks using the immediate caller's class loader instance". See Guideline 6-3 of Secure Coding Guidelines for the
Java Programming Language, version 2.0. The system class loader is in no way special in this case.
Just for kicks, I wrote a blog entry on this subject a while back. My solution, though more complicated then Nick Sayer's solution, is more complete and even works from untrusted code. Also note URLClassLoader.newInstance
is preferred over new URLClassLoader
.