What is the result of compiling and executing this code?

ITEM Table
* ID, INTEGER: PK
* DESCRIP, VARCHAR(100)
* PRICE, REAL
* QUALITY, INTEGER
And given the code fragment (assuming that the SQL query is valid):

What is the result of compiling and executing this code?

ITEM Table
* ID, INTEGER: PK
* DESCRIP, VARCHAR(100)
* PRICE, REAL
* QUALITY, INTEGER
And given the code fragment (assuming that the SQL query is valid):

What is the result of compiling and executing this code?

A.
An exception is thrown at runtime

B.
Compile fails

C.
The code prints Error

D.
The code prints information about Item 110

Explanation:

Tricky:
Compiles successfully ! Not B !
D is correct, if Column Quantity instead of Quality
Table Item Column Quality — System.out.println(“Quantity: ” + rs.getInt(“Quantity”));
wenn jedoch so gewollt: die Zeile gibt Error aus (die anderen funktionieren) !!!
The connection conn is not defined. The code will not compile.



Leave a Reply 7

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


Tim

Tim

C: Quality versus Quantity…

Humberto Bañuelos Flores

Humberto Bañuelos Flores

+1

aa

aa

shoulnt it be b?
As there is no connection

Ian

Ian

B?
Where is Connection type?
This code only have conn variable?

Freek

Freek

It says “code fragment”. Then you should assume it is declared and initialized properly.

CHIA

CHIA

A is correc

because without conn = DriverManager.getConnection(…)

May cause NullPointerException

SQLException can not catch it

So it can not print Error