How to deal with (maybe) null values in a PreparedStatement?

后端 未结 5 1907
不知归路
不知归路 2020-12-12 20:36

The statement is

SELECT * FROM tableA WHERE x = ?

and the parameter is inserted via java.sql.PreparedStatement \'stmt\'

stm         


        
5条回答
  •  -上瘾入骨i
    2020-12-12 21:21

    I've always done it the way you show in your question. Setting the same parameter twice is not such a huge hardship, is it?

    SELECT * FROM tableA WHERE x = ? OR (x IS NULL AND ? IS NULL);
    

提交回复
热议问题