轉自:Mars_idea 的 《不需要使用Class.forName()註冊數據庫的驅動也能加載到驅動》
原址:https://blog.csdn.net/Mars_idea/article/details/80754757
我們在使用jdbc操作數據庫時,一般會先註冊驅動,常用的方法就是使用
Class.forName("com.mysql.jdbc.Driver")
進行驅動的加載,但是最近卻發現不需要使用Class.forName()註冊數據庫的驅動也能正常使用。一直不知道爲何,網上搜了很多,發現在DriverManager類中有這樣一行註釋,
* <P>Applications no longer need to explicitly load JDBC drivers using <code>Class.forName()</code>. Existing programs
* which currently load JDBC drivers using <code>Class.forName()</code> will continue to work without
* modification.
所以說,不需要使用Class.forName()註冊數據庫的驅動也能加載到驅動。