exam questions

Exam 1z0-809 All Questions

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

Exam 1z0-809 topic 1 question 53 discussion

Actual exam question from Oracle's 1z0-809
Question #: 53
Topic #: 1
[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.
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.
Show Suggested Answer Hide Answer
Suggested Answer: C 🗳️

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
maslac
Highly Voted 3 years, 3 months ago
Corect answer is C. Error is: Operation not allowed after ResultSet closed. Because after executing the second query, the first one is automatically closed. Offical doc explanation: “A ResultSet object is automatically closed when the Statement object that generated it is closed, re-executed, or used to retrieve the next result from a sequence of multiple results. ” https://docs.oracle.com/javase/8/docs/api/java/sql/ResultSet.html
upvoted 8 times
cnno1
1 year, 3 months ago
You have the most words in your answer and I think you are right
upvoted 1 times
...
karta
1 year, 11 months ago
Absolutely!!
upvoted 1 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 next statement is run.
upvoted 1 times
...
r1muka5
1 year, 4 months ago
The answer is C
upvoted 1 times
...
WilsonKKerll
2 years, 4 months ago
Answer is C.
upvoted 2 times
...
mevlt
2 years, 5 months ago
The answer is B(tested). It seems no matter how many times you request ResultSet it will save the last one only.
upvoted 2 times
...
Svetleto13
3 years, 1 month ago
Correct answer is C
upvoted 3 times
...
Huim
3 years, 2 months ago
Answer is A
upvoted 1 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