Page 1 of 1

About Question enthuware.ocpjp.v11.2.3667 :

Posted: Wed Jul 21, 2021 11:35 am
by Stranko
Hi everyone,

Code: Select all

Incorrect response n1

ps.setNull(3, JDBCType.INTEGER); 
ps.setNull(4, JDBCType.STRING); 

The second parameter to the setNull method is of type int and it expects the value to be one of the constants defined in java.sql.Types class. Among other constants, [b]it has INTEGER and VARCHAR for int and String values respectively. STRING is not a valid constant in this class[/b].  java.sql.JDBCType also defines the same names (i.e. INTEGER and VARCHAR, among others) but it is an enum.
 
Incorrect response n2

ps.setNull(3, JDBCType.INTEGER); 
ps.setNull(4, [b]JDBCType.VARCHAR[/b]);

[b]This is wrong for the same reason as above[/b].
I'm sorry but this explanation doesn't make sense to me. "it has INTEGER and VARCHAR for int and String values respectively" vs second response being wrong despite having exactly VARCHAR described there?

Re: About Question enthuware.ocpjp.v11.2.3667 :

Posted: Wed Jul 21, 2021 11:52 pm
by admin
Please read the explanation carefully. The difference is in the name of the type in which INTEGER and VARCHAR are declared. i.e. Types.VARCHAR vs JDBCType.VARCHAR

Types.VARCHAR is an int while JDBCType.VARCHAR is an enum.

That is why the explanation says:
The second parameter to the setNull method is of type int and it expects the value to be one of the constants defined in java.sql.Types class.

Re: About Question enthuware.ocpjp.v11.2.3667 :

Posted: Fri Jul 23, 2021 1:20 pm
by Stranko
Alright, that clears it up, must have been too tired when reading the explanation.

Thanks :)