1Z0-809 practice question 17 of 25
Given the structure of the STUDENT table: Student (id INTEGER, name VARCHAR) Given: public class Test { static Connection newConnection =null; public…
Full set: 196 questionsThe getDBConnection method uses a try-with-resources statement. The Connection object con is created within the scope of this statement. When the try block completes, the connection is automatically closed because Connection implements AutoCloseable. The method then returns newConnection, which is a reference to this now-closed connection. In the main method, calling newConnection.createStatement() on a closed connection object will throw a SQLException, as operations are not permitted on a closed connection.
A. The program does not execute successfully because createStatement() is called on a closed connection, which is an invalid operation.
B. The program terminates with an exception before any update can be committed, and it would not execute successfully.
D. A NullPointerException is not thrown because newConnection holds a reference to a closed Connection object; it is not null.
1. Oracle Corporation. (2017). The try-with-resources Statement. The Java™ Tutorials. Retrieved from https://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html. (This document explains that resources declared in a try-with-resources statement are closed when the statement is finished).
2. Oracle Corporation. (2021). Interface Connection. Java® SE 17 Platform API Specification. Retrieved from https://docs.oracle.com/en/java/javase/17/docs/api/java.sql/java/sql/Connection.html#createStatement(). (The documentation for createStatement() specifies it throws an SQLException "if a database access error occurs or this method is called on a closed connection").
Keep practicing
Take the free 1Z0-809 practice test
Ten exam-style questions with answers and explanations, plus the exam facts and study guides.
More questions
Other 1Z0-809 practice questions
- Question 2Given: class Student { String course, name, city; public Student (String name, String cou…
- Question 3Given: class Worker extends Thread { CyclicBarrier cb; public Worker(CyclicBarrier cb) { …
- Question 4Given the code fragment: Path file = Paths.get (“courses.txt”); // line n1 Assume the cou…
- Question 5Given that /green.txt and /colors/yellow.txt are accessible, and the code fragment: Path …
- Question 6Given the code fragment:List<String> empDetails = Arrays.asList(“100, Robin, HR”,“200, Ma…
- Question 7Given the code fragment: List str = Arrays.asList (“my”, “pen”, “is”, “your’, “pen”); Pre…
