Given the code fragment:
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.
C
C
Corect answer is C. Error is: Operation not allowed after ResultSet closed.
Because after executing the second query, the first one is automatically closed.
This is also written in the official doc.
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
C
Б
A