1. 程式人生 > >不註冊驅動也能使用JDBC?

不註冊驅動也能使用JDBC?

轉自:Mars_idea 的 《不需要使用Class.forName()註冊資料庫的驅動也能載入到驅動》

我們在使用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()註冊資料庫的驅動也能載入到驅動。