1Z0-805 · Question #25
Given the code fragment: try { String query = "SELECT * FROM Employee WHERE ID=110"; Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery(query); // Line 13…
The correct answer is B. The code prints the employee ID. Assuming that the connection conn has been set up fine, the code will compile and run fine. Note#1: The GetInt method retrieves the value of the designated column in the current row of this ResultSet object as an int in the Java programming language. Note 2: A table of data…
Question
Given the code fragment:
try { String query = "SELECT * FROM Employee WHERE ID=110"; Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery(query); // Line 13 System.out.println("Employee ID: " + rs.getInt("ID")); // Line 14 } catch (Exception se) { System.out.println("Error"); } Oracle 1Z0-805 Exam Assume that the SQL query matches one record. What is the result of compiling and executing this code?
Options
- AThe code prints error.
- BThe code prints the employee ID.
- CCompilation fails due to an error at line 13.
- DCompilation fails due to an error at line 14.
How the community answered
(46 responses)- A15% (7)
- B76% (35)
- C4% (2)
- D4% (2)
Explanation
Assuming that the connection conn has been set up fine, the code will compile and run fine. Note#1: The GetInt method retrieves the value of the designated column in the current row of this ResultSet object as an int in the Java programming language. Note 2: A table of data representing a database result set, which is usually generated by executing a statement that queries the database. A ResultSet object maintains a cursor pointing to its current row of data. Initially the cursor is positioned before the first row. The next method moves the cursor to the next row, and because it returns false when there are no more rows in the ResultSet object, it can be used in a while loop to iterate through the result set. A default ResultSet object is not updatable and has a cursor that moves forward only. Thus, you can iterate through it only once and only from the first row to the last row. It is possible to produce ResultSet objects that are scrollable and/or updatable.
Topics
Community Discussion
No community discussion yet for this question.