exam questions

Exam 1z0-809 All Questions

View all questions & answers for the 1z0-809 exam

Exam 1z0-809 topic 1 question 20 discussion

Actual exam question from Oracle's 1z0-809
Question #: 28
Topic #: 2
[All 1z0-809 Questions]

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.
dbURL, userName, and passWord exists.
The appropriate database is accessible with the
Employee and Customer tables are available and each table has id column with a few records and the SQL queries are valid.

The -
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.
Show Suggested Answer Hide Answer
Suggested Answer: D 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
M_Jawad
Highly Voted 4 years, 6 months ago
it will print Error The 13th line of the program uses the executeQuery method of the Statement object again, which will cause the previous ResultSet to be automatically closed, so the 14th line of the program will throw a SQLException.
upvoted 10 times
...
asdfjhfgjuaDCV
Most Recent 4 months, 3 weeks ago
C is the answer
upvoted 1 times
...
steefaand
5 months, 3 weeks ago
Selected Answer: C
C is correct, as ResultSet is closed once the new statement is run and it throws exception.
upvoted 1 times
...
iSnover
5 months, 3 weeks ago
Selected Answer: C
Answer is C. The 13th line of the program uses the executeQuery method of the Statement object again, which will cause the previous ResultSet to be automatically closed, so the 14th line of the program will throw a SQLException.
upvoted 1 times
...
WilsonKKerll
2 years, 4 months ago
Answer is C.
upvoted 1 times
...
Uchiha
2 years, 4 months ago
Answer is C
upvoted 1 times
...
mevlt
2 years, 4 months ago
The answer is B(tested)
upvoted 1 times
mevlt
2 years, 4 months ago
Second statement overrides.
upvoted 1 times
...
...
adnano1234
4 years, 6 months ago
A. The program prints employee IDs.
upvoted 1 times
adnano1234
4 years, 6 months ago
Sorry, the program prints Error as explained by M_Jawad
upvoted 3 times
...
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago