1Z0-809 · Question #220
Which code fragment is required to load a JDBC 3.0 driver?
The correct answer is B. Class.forName("org.xyzdata.jdbc.NetworkDriver"). Option B is correct because in JDBC 3.0 (and earlier), drivers must be explicitly registered with the DriverManager by loading the driver class into the JVM using Class.forName(). This call triggers the class's static initializer, which registers the driver instance with…
Question
Options
- AConnection con = Connection.getDriver ("jdbc:xyzdata://localhost:3306/EmployeeDB");
- BClass.forName("org.xyzdata.jdbc.NetworkDriver");
- CConnection con = DriverManager.getConnection ("jdbc:xyzdata://localhost:3306/EmployeeDB");
- DDriverManager.loadDriver ("org.xyzdata.jdbc.NetworkDriver");
How the community answered
(45 responses)- A4% (2)
- B84% (38)
- C2% (1)
- D9% (4)
Explanation
Option B is correct because in JDBC 3.0 (and earlier), drivers must be explicitly registered with the DriverManager by loading the driver class into the JVM using Class.forName(). This call triggers the class's static initializer, which registers the driver instance with DriverManager automatically - making it available for subsequent connection calls.
Why the distractors are wrong:
- A -
Connection.getDriver()is not a real method;Connectionis an interface for managing a database session, not for locating drivers. - C -
DriverManager.getConnection()establishes a connection but does not load the driver; it requires the driver to already be registered (which is what B accomplishes). - D -
DriverManager.loadDriver()does not exist in the JDBC API; this is a fabricated method name.
Memory tip: Think of it in two steps - load then connect. Class.forName() loads (registers) the driver; DriverManager.getConnection() uses it. The exam question asks specifically about loading, so the answer is always the Class.forName() call. Note: JDBC 4.0+ introduced auto-loading via ServiceLoader, but JDBC 3.0 requires the explicit Class.forName().
Community Discussion
No community discussion yet for this question.