咱们能够用自定义的 URLClassLoader 从外部动态加载类,并使用它。但数据库驱动的管理类 DriverManager 却不比较苛刻,不认可非当前应用系统加载器加载的驱动类。见 DriverManager 的 JavaDoc html
When the method
getConnection
is called, theDriverManager
will attempt to locate a suitable driver from amongst those loaded at initialization and those loaded explicitly using the same classloader as the current applet or applicationjava
对于有有应用自定义类加载器加载数据库驱动类的需求时,就要对原 Driver 简单包装一下。继续日后会说介绍为何要这么作。sql
说明一下,DriverManager 可以根据 JDBC 链接字符串匹配到驱动类,因此通常来讲都不须要显式调用 DriverManager.registerDriver() 方法。数据库
先看 DriverManager 在应用外部驱动类时会出现什么状况 阅读全文 >>api