Which action can be used to load a database driver by using JDBC3.0?
A. Add the driver class to the META-INF/services folder of the JAR file.
B. Include the JDBC driver class in a jdbc.properties file.
C. Use the java.lang.Class.forName method to load the driver class.
D. Use the DriverManager.getDriver method to load the driver class.
題解
JDBC4.0 之前,載入 Driver 的方式就是使用 Class 類別的 forName 方法,在參數指定 Driver 的名稱(類別路徑),程式會自動呼叫 DriverManager 類別的 registerDriver 方法來載入(註冊)Driver。
選項 A,這是 JDBC4.0 的機制,要將 Driver 的名稱寫進「META-INF/services/java.sql.Driver」檔案內,即可自動載入。
選項 B,沒有這樣的用法。
選項 C,正確載入 Driver 的方式。
選項 D,DriverManager 類別的 getDriver 方法只是用來取得已經載入的 Driver 物件。
