How to use a JDBC driver from an arbitrary location

后端 未结 2 716
盖世英雄少女心
盖世英雄少女心 2020-12-03 05:35

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         


        
2条回答
  •  离开以前
    2020-12-03 06:05

    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.

提交回复
热议问题