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.
C: Quality versus Quantity…
+1
C
shoulnt it be b?
As there is no connection
B?
Where is Connection type?
This code only have conn variable?
It says “code fragment”. Then you should assume it is declared and initialized properly.
A is correc
because without conn = DriverManager.getConnection(…)
May cause NullPointerException
SQLException can not catch it
So it can not print Error