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

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.

dbURL, userName, and passWord exists.

The appropriate database is accessible with the

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 print statement at line 18. The line 18 contains a missing double quote before the text 'Quantity'. The correct line should be System.out.println("Quantity: " + rs.getInt("Quantity")); without this correction the code will not compile, hence leading to a runtime exception.

Discussion
thetechOption: D

Answer is D. Tested

johnchen88Option: C

The correct answer should be C: since it does not say the id 110 is existing in the database, the sql is valid that does not mean it is existing

iSnover

Sorry, the last line of the question says that the query is valid. The answer is D.

steefaandOption: D

D is true assuming there is record in database.

iSnoverOption: D

Answer is D. Tested.

UchihaOption: D

Answer is D