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 { } static { try { DriverManager.registerDriver(new Driver()); } catch (SQLException var1) { throw new RuntimeException("Can't register driver!"); } } }
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进行了简单的继承。