本文主要是介绍DriverManager 源码分析,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1. Class.forName("com.mysql.jdbc.Driver");
在初始化的时候会执行注册当前Driver给DriverManager
static {try {java.sql.DriverManager.registerDriver(new Driver());} catch (SQLException E) {throw new RuntimeException("Can't register driver!");}}
2. Connection connection = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/xxxx");
遍历所有的registeredDrivers链接成功则直接返回,失败则继续下一个
for(DriverInfo aDriver : registeredDrivers) {// If the caller does not have permission to load the driver then// skip it.if(isDriverAllowed(aDriver.driver, callerCL)) {try {println(" trying " + aDriver.driver.getClass().getName());Connection con = aDriver.driver.connect(url, info);
这篇关于DriverManager 源码分析的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!