Which code fragment demonstrates the proper way to handle JDBC resources?

Which code fragment demonstrates the proper way to handle JDBC resources?

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) {}



Leave a Reply 2

Your email address will not be published. Required fields are marked *


bob

bob

The marked correct answer B does not compile …