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

[553 byte] By [belingueresa] at [2007-10-2 17:48:26]
# 1

> 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.

belingueresa at 2007-7-13 19:06:27 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2

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.

DrClapa at 2007-7-13 19:06:27 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 3
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.
lanceaa at 2007-7-13 19:06:27 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...