Is "IS NULL" conversion automatic?
Hi,
Suppose I have the following sentence:
PreparedStatement ps =
connection.prepareStatement(
"select firstname,lastname from persona where birthdate=?");
ps.setDate(1,null);
ps.executeQuery();
I wonder if the where "birthdate=xx" part of the query is AUTOMATICALLY converted by the JDBC driver to "birthdate is null" when detecting NULL as a paremeter.
Which would be the correct behavior of a JDBC driver?
Regards,
Gabriel
> I wonder if the where "birthdate=xx" part of the
> query is AUTOMATICALLY converted by the JDBC driver
> to "birthdate is null" when detecting NULL as a
> paremeter.
No.
>
> Which would be the correct behavior of a JDBC
> driver?
>
An error I would say.
You could try setNull but I don't know. Mostly all that you do is bind the actual parameters not change what the SQL looks like. Since you want to change = into IS NULL I have some doubts.
SQL does define what it means to compare values that may be null, so my guess is that a compliant JDBC driver would pass something equivalent to "...where birthdate=null" to the database. And since SQL's definition of comparing X to null always results in false, the query would return zero rows.
no it is int done automatically. Your SQL needs to be correct for the underlying data store. setting a parameter is just that, you are specifying the value, nothing more.