不加载驱动是怎么连的?A call to forName("X") causes the class named X to be initialized. 它返回的是X类的运行时Class discriptor 其内部涉及到获取ClassLoader// Returns the invoker's class loader, or null if none. // NOTE: This must always be invoked when there is exactly one intervening // frame from the core libraries on the stack between this method's // invocation and the desired invoker. static ClassLoader getCallerClassLoader() { // NOTE use of more generic Reflection.getCallerClass() Class caller = Reflection.getCallerClass(3); // This can be null if the VM is requesting it if (caller == null) { return null; } // Circumvent security check since this is package-private return caller.getClassLoader0(); }假如forName是在Test类中调用的,caller就是Test类Class对象
Oracle 支持 JDBC 4 驱动版本是 ojdbc6.jar
MS SQL Server 支持 JDBC 4 驱动版本是 Microsoft SQL Server JDBC Driver 2.0PS:com.gjt.mm.mysql.Driver 已经是很老的驱动了,那是 MySQL JDBC 驱动的作者 Mark Matthews 在加盟 MySQL 之前所使用的驱动,其中的 mm 就是作者的名字。在 Mark Matthews 加盟 MySQL 之后就改名为 Connector/J,驱动类名也改用 com.mysql.jdbc.Driver,而 mm 的驱动不再更新。目前,所有的 MySQL 驱动包都为了兼容性而保留了 com.gjt.mm.mysql.Driver,但是新开发的程序应使用 com.mysql.jdbc.Driver。
package org.gjt.mm.mysql;import java.sql.SQLException;public class Driver extends com.mysql.jdbc.Driver
{
}
package com.mysql.jdbc;import java.sql.DriverManager;
import java.sql.SQLException;public class Driver extends NonRegisteringDriver
implements java.sql.Driver
{
static
{
try
{
DriverManager.registerDriver(new Driver());
} catch (SQLException E) {
throw new RuntimeException("Can't register driver!");
}
}}
它返回的是X类的运行时Class discriptor 其内部涉及到获取ClassLoader// Returns the invoker's class loader, or null if none.
// NOTE: This must always be invoked when there is exactly one intervening
// frame from the core libraries on the stack between this method's
// invocation and the desired invoker.
static ClassLoader getCallerClassLoader() {
// NOTE use of more generic Reflection.getCallerClass()
Class caller = Reflection.getCallerClass(3);
// This can be null if the VM is requesting it
if (caller == null) {
return null;
}
// Circumvent security check since this is package-private
return caller.getClassLoader0();
}假如forName是在Test类中调用的,caller就是Test类Class对象