Which code fragment demonstrates the proper way to handle JDBC resources?
A.
try { Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery (query);
while (rs.next()) (/* . . . */) } catch (SQLException e) {}
B.
try { Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery (query);
while (rs.next()) (/* . . . */) } finally { rs.close(); stmt.close(); }
C.
try { ResultSet rs = stmt.executeQuery (query); Statement stmt = con.createStatement();
while (rs.next()) (/* . . . */) } finally { rs.close(); stmt.close(); }
D.
try { ResultSet rs = stmt.executeQuery (query); statement stmt = con.createStatement();
while (rs.next()) (/* . . . */) } catch (SQLException e) {}
The marked correct answer B does not compile …
A