JDBC DriverManager
java的包下,驱动程序管理器类DriverManager负责管理驱动程序,Java访问数据的过程就是通过实现了JDBC规范的驱动实现类来访问数据的过程,java通过DriverManager来与不同数据库的驱动交互帮助它们实现数据正常访问过程(我们一直在做的建立连接,执行方法)
registerDriver 注册Driver
public static synchronized void registerDriver(java.sql.Driver driver,DriverAction da)
这个过程实际上就是将我们的Driver对象作为入参然后转化为一个修饰类 DriverInfo,然后放入DriverManager的已注册Driver的List数据结构保存。
Connection连接
getConnection(String url, String user, String password) 建立连接
/**
* Attempts to establish a connection to the given database URL.
* The <code>DriverManager</code> attempts to select an appropriate driver from
* the set of registered JDBC drivers.
*<p>
* <B>Note:</B> If the {@code user} or {@code password} property are
* also specified as part of the {@code url}, it is
* implementation-defined as to which value will take precedence.
* For maximum portability, an application should only specify a
* property once.
*
* @param url a database url of the form
* <code>jdbc:<em>subprotocol</em>:<em>subname</em></code>
* @param user the database user on whose behalf the connection is being
* made
* @param password the user's password
* @return a connection to the URL
* @exception SQLException if a database access error occurs or the url is
* {@code null}
* @throws SQLTimeoutException when the driver has determined that the
* timeout value specified by the {@code setLoginTimeout} method
* has been exceeded and has at least tried to cancel the
* current database connection attempt
*/
@CallerSensitive
public static Connection getConnection(String url,
String user, String password) throws SQLException {
java.util.Properties info = new java.util.Properties(