Java PreparedStatement allows you to set a value for a given parameter or to set it to NULL
SELECT *
FROM ADDRESS
WHERE ADDRESS_LINE1 = ?
so we could write code to set this parameter:
if (addressLine1 != null) {
preparedStatement.setString(1, addressLine1);
} else {
preparedStatement.setNull(1, VARCHAR);
}
however it is also declared that you should never compare a value to null using the = operator and actually use the IS operator for null comparisons.
Is the prepared statement actually swapping the = operator for IS under the covers here or is the null just being inserted still using the = operator? If the latter then when is it ever useful to use this and are you actually getting the expected outcome?
I am asking this on the back of the following stack overflow question