Java SE 8 Programmer II — Question 197
Which code fragment is required to load a JDBC 3.0 driver?
Answer options
- A. Connection con = Connection.getDriver ("jdbc:xyzdata://localhost:3306/EmployeeDB");
- B. Class.forName("org.xyzdata.jdbc.NetworkDriver");
- C. Connection con = DriverManager.getConnection ("jdbc:xyzdata://localhost:3306/EmployeeDB");
- D. DriverManager.loadDriver ("org.xyzdata.jdbc.NetworkDriver");
Correct answer: B
Explanation
The correct answer is B because the Class.forName method is used to load the JDBC driver class specified by its name. The other options either incorrectly attempt to load the driver or establish a connection without first loading the driver class.