1z0-809 question 53 discussion

View all Java SE 8 Programmer II Exam here
back to oracle forum

Question 53

Given the code fragment:
9. Connection conn = DriveManager.getConnection(dbURL, userName, passWord);
10. String query = SELECT id FROM Employee;
11. try (Statement stmt = conn.createStatement()) {
12. ResultSet rs = stmt.executeQuery(query);
13.stmt.executeQuery(SELECT id FROM Customer);
14. while (rs.next()) {
15. //process the results
16.System.out.println(Employee ID: + rs.getInt(id));
17.}
18. } catch (Exception e) {
19. System.out.println (Error);
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?

  • A. The program prints employee IDs.
  • B. The program prints customer IDs.
  • C. The program prints Error.
  • D. compilation fails on line 13.
Answer:

C

User Votes:
A
50%
B
50%
C
50%
D 1 votes
50%
Discussions
0 / 1000
vidhya
6 months, 3 weeks ago

The resultset can handle only one statement at once. if u want assign another query then use another statement2 and another resultset. or u can close the previous resultset and fire the second statement in the same result set. so it is a compilation error on line 13 , it fails to go to catch block