Exam 1z0-809 All QuestionsBrowse all questions from this exam
Question 56

Given:

Item table -

"¢ ID, INTEGER: PK

"¢ DESCRIP, VARCHAR(100)

"¢ PRICE, REAL

"¢ QUANTITY< INTEGER

And given the code fragment:

9. try {

10. Connection conn = DriveManager.getConnection(dbURL, username, password);

11. String query = "Select * FROM Item WHERE ID = 110";

12. Statement stmt = conn.createStatement();

13. ResultSet rs = stmt.executeQuery(query);

14. while(rs.next()) {

15. System.out.println("ID: " + rs.getInt("Id"));

16. System.out.println("Description: " + rs.getString("Descrip"));

17. System.out.println("Price: " + rs.getDouble("Price"));

18. System.out.println(Quantity: " + rs.getInt("Quantity"));

19. }

20. } catch (SQLException se) {

21. System.out.println("Error");

22. }

Assume that:

The required database driver is configured in the classpath.

The appropriate database is accessible with the dbURL, userName, and passWord exists.

The SQL query is valid.

What is the result?

    Correct Answer: A

    An exception is thrown at runtime due to a syntax error in the System.out.println statement on line 18. The concatenation operator "+" is missing before starting the string in the 'Quantity:' message.

Discussion
Svetleto13Option: D

D is correct answer

lchowenOption: D

D is correct. According to the official Java Doc, Column names used as input to getter methods are case insensitive. Reference : https://docs.oracle.com/javase/8/docs/api/java/sql/ResultSet.html

asdfjhfgjuaDCVOption: D

D is the Correct answer

steefaandOption: D

Assuming that DriveManager is typo and is instead DriverManager, correct answer is D.

WilsonKKerllOption: D

Answer is D.

iamajavacompilerOption: D

Is D correct?