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…
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)- A2% (1)
- B12% (6)
- C76% (39)
- E6% (3)
- F4% (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
Community Discussion
No community discussion yet for this question.