第1个回答 推荐于2017-09-24
getClass().getClassLoader().loadClass("com.mysql.jdbc.Driver"),就不行。 为什么呢?打开com.mysql.jdbc.Driver的源代码看看, // // Register ourselves with the DriverManager // static { try { java.sql.DriverManager.registerDriver(new Driver()); } catch (SQLException E) { throw new RuntimeException("Can't register driver!"); } } 原来,Driver在static块中会注册自己到java.sql.DriverManager。