com.mysql.jdbc.Driver的前身是org.gjt.mm.mysql.Driver,现在主要用com.mysql.jdbc.Driver,但为了保持兼容性保留了org.gjt.mm.mysql.Driver这个路径的引用。
mysql-connector-java-5.1.40.jar包结构:
com.mysql.jdbc.Driver.java 代码:
package com.mysql.jdbc; import java.sql.DriverManager;
import java.sql.SQLException; public class Driver extends NonRegisteringDriver implements java.sql.Driver {
public Driver() throws SQLException {
}</span><span style="color: #0000ff;">static</span><span style="color: #000000;"> { </span><span style="color: #0000ff;">try</span><span style="color: #000000;"> { DriverManager.registerDriver(</span><span style="color: #0000ff;">new</span><span style="color: #000000;"> Driver()); } </span><span style="color: #0000ff;">catch</span><span style="color: #000000;"> (SQLException var1) { </span><span style="color: #0000ff;">throw</span> <span style="color: #0000ff;">new</span> RuntimeException("Can't register driver!"<span style="color: #000000;">); } }
}
org.gjt.mm.mysql.Driver.java 代码:
package org.gjt.mm.mysql; import java.sql.SQLException; public class Driver extends com.mysql.jdbc.Driver {
public Driver() throws SQLException {
}
}
可以总结出MySQL公司为了保持兼容性让org.gjt.mm.mysql.Driver对com.mysql.jdbc.Driver进行了简单的继承。
原文地址:https://www.cnblogs.com/JimKing/p/9032272.html