In Mysql there is a compare operator that is a null safe: <=>. I use this in my Java program when creating prepared statements like this:
String routerAddress = getSomeValue();
String sql = "SELECT * FROM ROUTERS WHERE ROUTER_ADDRESS <=> ? ";
PreparedStatement stmt = connection.prepareStatement(sql);
stmt.setString(1, routerAddress);
Now I would like to switch to the H2 database. How do I write the <=> operator in pure SQL (using for example IS NULL and IS NOT NULL)? I would like use the stmt.setString operation only once. It is okay to write the column name several times.
Related question is Get null == null in SQL. But that answer requires the search value to be written 2 times (that is: 2 question marks in my PreparedStatement)!?
Reference: http://dev.mysql.com/doc/refman/5.0/en/comparison-operators.html#operator_equal-to
a is distinct from b
– Cainozoic