Oracle
1Z0-809 · Question #88
Given the code fragment: 9. Connection conn = DriverManager.getConnection (dbURL, userName, password); 10. String query = "SELECT id FROM Employee"; 11. try (Statement stmt = conn.createStatement())…
The correct answer is C. The program prints Exception. See the full explanation below for the reasoning.
Question
Given the code fragment:
9. Connection conn = DriverManager.getConnection (dbURL, userName, password);
10. String query = "SELECT id FROM Employee";
11. try (Statement stmt = conn.createStatement()) {
12. ResultSet rs = stmt.executeQuery(query);
13. rs = stmt.executeQuery("SELECT id FROM Customer");
14. while (rs.next()) {
15. //process the results
16. System.out.println("Employee ID: " + rs.getInt("id"));
17. }
} catch (Exception e) {
18. System.out.println ("Error");
19. }
20. }
Assume that:
- The required database driver is configured in the classpath.
- The appropriate database is accessible with the dbURL, userName, and password exists.
- The Employee and Customer tables are available and each table has id column with a few records and the SQL queries are valid. What is the result of compiling and executing this code fragment?
Options
- AThe program prints employee IDs.
- BThe program prints customer IDs.
- CThe program prints Exception.
- Dcompilation fails on line 13.
How the community answered
(18 responses)- A6% (1)
- B11% (2)
- C78% (14)
- D6% (1)
Community Discussion
No community discussion yet for this question.