Page 1 of 1

Re: About Question enthuware.ocpjp.v11.-2-.3667 :

Posted: Fri May 28, 2021 6:18 pm
by bdshadow
could you, please add an explanation why the second option is incorrect:

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

i didn't get from other explanations why it is wrong

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

Posted: Fri May 28, 2021 10:23 pm
by admin
It is wrong for the exact same reason option 1 is wrong. Already explained in detail:
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, it has INTEGER and VARCHAR for int and String values respectively. STRING is not a valid constant in this class.

java.sql.JDBCType also defines the same names (i.e. INTEGER and VARCHAR, among others) but it is an enum.

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

Posted: Tue Jun 15, 2021 10:14 am
by bdshadow
The first option is wrong, because it has "ps.setNull(4, JDBCType.STRING);", where JDBCType.STRING is not a valid constant.

Also the first option is different from the 2nd in only one line, which is "ps.setNull(4, JDBCType.VARCHAR);" in the second line. And it is correct. JDBCType has VARCHAR as value. So why it is wrong?

Sorry if i'm missing smth

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

Posted: Tue Jun 15, 2021 10:18 am
by bdshadow
sorry, i got it. The type itself is incorrect. It must be java.sql.Types class