What is true about the following code? (Choose two.)
public static void main(String[] args) throws Exception { String url = "jdbc:derby:hats;create=true"; Connection conn = null; /*from w w w . j a v a 2 s . co m*/ Statement stmt = null; try { conn = DriverManager.getConnection(url); stmt = conn.createStatement(); stmt.executeUpdate( "CREATE TABLE caps (name varchar(255), size varchar(1))"); } finally { conn.close(); stmt.close(); } }
A, C.
JDBC 3.0 drivers require a Class.forName()
call.
Since this is missing, Option A is correct, and Option B is incorrect.
The Connection and Statement creation are correct, making Options E and F incorrect.
Since the call to stmt
.close()
should be before the call to conn
.close()
, Option C is correct, and Option D is incorrect.