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

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.getString(1));

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

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

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

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: B

    The code will fail to compile due to a syntax error at line 18. It is missing a closing quotation mark at 'System.out.println(Quantity: '.

Discussion
PontPontOption: A

15. System.out.println("ID: " + rs.getString(1));' ID is integer not string.

grigladOption: D

Although the value of the ID field is int, it can still be retrieved using getString().

jduarteOption: B

Line 18 is missing a quotation mark. The correct answer is b

asdfjhfgjuaDCVOption: D

D is the Correct answer

steefaandOption: D

Answer is D as getString can be used to retrieve data of other types.

iSnoverOption: D

As column ID defined by INTEGER, but you can get it by getString("<column name>").

duydnOption: D

The answer is D. As column ID defined by INTEGER, but you can get it by getString("<column name>") line 18 I think is typo -> D

WilsonKKerllOption: D

Answer is d.

mevltOption: D

Answer is D