Suppose the blue database exists and we are using a JDBC 4.0 driver.
Which is the outcome of this code?
String url = "jdbc:derby:blue"; Class.forName(url); try (Connection conn = DriverManager.getConnection(url); Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("select count(*) from sky")) { System.out.println(rs.getInt(1)); }
B.
JDBC 4.0 allows, but does not require, a call to the Class.forName()
method.
However, since it is in the code, it needs to be correct.
This method is expecting a fully qualified class name of a database driver, not the JDBC URL.
The Class.forName()
method throws a ClassNotFoundException, and Option B is the answer.