![]() ![]() |
|
JDBC到底是怎么连上数据库的 | |
作者:佚名 文章来源:不详 点击数 更新时间:2008/5/9 19:02:05 文章录入:杜斌 责任编辑:杜斌 | |
|
|
JDBC到底是怎么连上数据库的 Java.sql包中的 java.sql.Driver, jdbc.sql.Connection等提供给程序开发人员统一的开发接口 1 Class.forName(String classname) 的源码为: 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); } return (getConnection(url, info, callerCL)); } private static synchronized Connection getConnection( String url, java.util.Properties info, ClassLoader callerCL) throws SQLException { ... Connection result = di.driver.connect(url, info); ... } } |
|
![]() ![]() |