1Z0-809 practice question 21 of 25
Given: Item table • ID, INTEGER: PK • DESCRIP, VARCHAR(100) • PRICE, REAL • QUANTITY< INTEGER And given the code fragment: 9. try { 10.Connection…
Full set: 196 questionsThe code will successfully connect to the database and execute the query. The ResultSet.getXXX(String columnLabel) methods are specified to be case-insensitive when looking up column names. Therefore, rs.getInt("Id") will correctly map to the ID column, rs.getString("Descrip") to DESCRIP, and so on. Assuming a record with ID = 110 exists in the Item table, the while(rs.next()) loop will execute, and the details of that item will be printed to the console. The code is syntactically correct and uses the JDBC API as intended.
A. No exception is expected, as the use of case-insensitive column labels in getXXX methods is standard JDBC behavior.
B. The code is syntactically valid and will compile, assuming the missing quote before "Quantity:" is a transcription error in the question.
C. The "Error" message is only printed if a SQLException is caught. The operations shown are standard and should not cause an exception.
- JDBC™ 4.2 API Specification. (2014). JSR-221, Maintenance Release 2. Section 15.2.2, "Retrieving Column Values from Result Sets," states: "A column may be referenced by its name or by its index. The column name is case-insensitive."
- Oracle. (2017). Java SE 8 API Documentation, java.sql.ResultSet interface. While the API doc itself does not explicitly state case-insensitivity, it is a requirement defined by the overarching JDBC Specification that compliant drivers must follow.
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…
