Which code fragment is required to load a JDBC 3.0 driver?
Click on the arrows to vote for the correct answer
A. B. C. D.B.
The correct answer is B. Class.forName("org.xyzdata.jdbc.NetworkDriver").
Explanation:
To use a JDBC driver, the driver class needs to be loaded and registered with the DriverManager. In this question, the driver is a JDBC 3.0 driver, which means that it is compatible with JDBC 3.0 and higher.
Option A is incorrect because the Connection class does not have a static method called getDriver(). Instead, the DriverManager class has a method called getDriver().
Option C is incorrect because it uses the getConnection() method of the DriverManager class to get a connection, but it does not load or register the driver with the DriverManager.
Option D is incorrect because the DriverManager class does not have a static method called loadDriver(). Instead, the Class.forName() method is used to load the driver class.
Option B is the correct answer because it uses the Class.forName() method to load the driver class and register it with the DriverManager. Once the driver class is loaded, the DriverManager can be used to obtain a connection to the database using the appropriate URL.
Note that in modern JDBC code, the Class.forName() call is not strictly necessary, as the driver is often loaded automatically when the application starts up. However, the Class.forName() call is still included in many older JDBC examples and tutorials.