What happens with setString and null values?
843854May 20 2002 — edited May 20 2002Hi,
I seem to be experiencing some strange behaviour with PreparedStatements and setString that I can't quite explain and would appreciate if somebody could help.
I am running JDK1.3.1 on Windows NT 4 using JDBC-ODBC to interact with our SQL Server 7 database.
I have a PreparedStatement which is expecting a string e.g.
String var;
...
PreparedStatement ps = cn.prepareStatement("SELECT X FROM Y WHERE W = ?");
ps.setString(1, var);
If var has a valid value then eveything works fine, however sometimes var can be null. In this case, I would have expected this statement to either
a) return nothing (what the code currently assumes) or
b) throw an error since the proper syntax should be SELECT X FROM Y WHERE W IS NULL.
The strange thing is sometimes this statement works when var is null returing all rows where w is null. This doesn't happen all the time, just sometimes.
My question is, what should I expect if var is null?
Thanks.