nerdexam
Oracle

1Z0-805 · Question #6

Given this code fragment: ResultSet rs = null; try (Connection conn = DriverManager. getConnection (url) ) { Statement stmt = conn.createStatement(); rs stmt.executeQuery(query); //-.. other methods…

The correct answer is C. The Result set object only. Generally, JavaScript has just 2 levels of scope: global and function. But, try/catch is an exception (no punn intended). When an exception is thrown and the exception object gets a variable assigned to it, that object variable is only available within the "catch" section and…

Building Database Applications with JDBC

Question

Given this code fragment:

ResultSet rs = null; try (Connection conn = DriverManager. getConnection (url) ) { Statement stmt = conn.createStatement(); rs stmt.executeQuery(query); //-.. other methods } } catch (SQLException se) { System.out.println ("Error"); } Which object is valid after the try block runs?

Options

  • AThe Connection object only
  • BThe Statement object only
  • CThe Result set object only
  • DThe Statement and Result Set object only
  • EThe connection, statement, and ResultSet objects
  • FNeither the Connection, Statement, nor ResultSet objects

How the community answered

(51 responses)
  • A
    2% (1)
  • B
    12% (6)
  • C
    76% (39)
  • E
    6% (3)
  • F
    4% (2)

Explanation

Generally, JavaScript has just 2 levels of scope: global and function. But, try/catch is an exception (no punn intended). When an exception is thrown and the exception object gets a variable assigned to it, that object variable is only available within the "catch" section and is destroyed as soon as the catch completes.

Topics

#ResultSet scope#try-with-resources#Connection lifecycle#JDBC resources

Community Discussion

No community discussion yet for this question.

Full 1Z0-805 Practice