Java PreparedStatement provides a possibility to explicitely set a Null value. This possibility is:
prepStmt.setNull(parameterIndex, Types.VARCHAR);
Are the semantics of this call the same as when using a specific setType with a null parameter?
prepStmt.setString(null);
?
Advertisement
Answer
This guide says:
6.1.5 Sending JDBC NULL as an IN parameter
The
setNullmethod allows a programmer to send a JDBCNULL(a generic SQLNULL) value to the database as an IN parameter. Note, however, that one must still specify the JDBC type of the parameter.A JDBC
NULLwill also be sent to the database when a Javanullvalue is passed to asetXXXmethod (if it takes Java objects as arguments). The methodsetObject, however, can take anullvalue only if the JDBC type is specified.
So yes they’re equivalent.