1 Class.forName(String classname) 的源码为: public final class Class implements java.io.Serializable { ... public static Class forName(String className) throws ClassNotFoundException { return forName0(className, true, ClassLoader.getCallerClassLoader()); }
2 sun的JdbcOdbcDriver 源码: public class JdbcOdbcDriver extends JdbcOdbcObject implements JdbcOdbcDriverInterface { ... /** * connect to DB */ public synchronized Connection connect(String s, PRoperties properties) throws SQLException { if(JdbcOdbcObject.isTracing()) JdbcOdbcObject.trace("*Driver.connect (" + s + ")"); if(!acceptsURL(s)) return null; if(hDbc != 0) { disconnect(hDbc); closeConnection(hDbc); hDbc = 0; } if(!initialize()) { return null; } else { JdbcOdbcConnection jdbcodbcconnection = new JdbcOdbcConnection(OdbcApi, hEnv, this); jdbcodbcconnection.initialize(getSubName(s), properties, DriverManager.getLoginTimeout()); jdbcodbcconnection.setURL(s); return jdbcodbcconnection; } }
static { if(JdbcOdbcObject.isTracing()) JdbcOdbcObject.trace("JdbcOdbcDriver class loaded"); JdbcOdbcDriver jdbcodbcdriver = new JdbcOdbcDriver(); try { DriverManager.registerDriver(jdbcodbcdriver); } catch(SQLException sqlexception) { if(JdbcOdbcObject.isTracing()) JdbcOdbcObject.trace("Unable to register driver"); } } }
public interface JdbcOdbcDriverInterface extends Driver { ... }
3 连接过程 jdbc.sql.Connection con = DriverManager.getConnection("jdbc:odbc:pubs","sa","");
public class DriverManager { public static synchronized Connection getConnection(String url, String user, String passWord) throws SQLException { java.util.Properties info = new java.util.Properties();
// Gets the classloader of the code that called this method, may // be null. ClassLoader callerCL = DriverManager.getCallerClassLoader();
if (user != null) { info.put("user", user); } if (password != null) { info.put("password", password); }