Assume that the SQL queries return records. 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 ***
Explanation:
!!! The given Code prints Error — the second query clears the ResultSet !? ErrorMessage:
Operation notallowed after ResultSet closed
It would print A, if second Query i set to rs = stmt.executeQuery(“SELECT ID FROM Customer”); //
Line ***
It would print B, if Line *** is missing. //
The program compiles and runs fine. Both executeQuery statements will run. The first
executeQuery statement
(ResultSet rs = stmt.executeQuery(query);) will set the rs Resultset. It will be used in the while
loop. EmployIDswill be printed.
Note:
Executes the given SQL statement, which returns a single ResultSet object.
Parameters:sql – an SQL statement to be sent to the database, typically a static SQL SELECT
statement Returns:a ResultSet object that contains the data produced by the given query; never
null
Should be A?
SQL Exception: java.sql.SQLException: Operation not allowed after ResultSet closed
A
It’s C