What is the result?

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?

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?

A.
An exception is thrown at runtime.

B.
Compilation fails.

C.
The code prints Error.

D.
The code prints information about Item 110.



Leave a Reply 4

Your email address will not be published. Required fields are marked *


smh

smh

C.
The code prints Error.

smh

smh

Sorry my earlier answer c is wrong.
D is the correct answer.
The code prints information about Item 110.