publicclassDriverextendsNonRegisteringDriverimplementsjava.sql.Driver{//// Register ourselves with the DriverManager// 在.class文件加载到内存时运行,并且有且只执行一次// 代码初始化过程!!!static{try{// DriverManager驱动管理器注册了当前com.mysql.jdbc.Driver// 相对于当前Java程序拥有了连接MySQL数据库的必要的驱动条件
java.sql.DriverManager.registerDriver(newDriver());}catch(SQLException E){thrownewRuntimeException("Can't register driver!");}}/**
* Construct a new driver and register it with DriverManager
*
* @throws SQLException
* if a database error occurs.
*/publicDriver()throws SQLException {// Required for Class.forName().newInstance()}}