关于String的replace替换问题

来源:百度知道 编辑:UC知道 时间:2024/06/23 20:19:37
我有一个sql语句:

SQL codeselect count(*) from Cstcustom c, CstCustomManager cm where cm.userID = ? and cm.customID = c.ID and c.sourceid = ? and cm.customID not in (select cm2.customID from CstCustomManager cm2 where cm2.userID = ?)

要求在find方法中传过来的是该sql和一个object[]参数,按以上语句,应该传过来的是一个含有三个元素的数组,分别代表三个?,但是在oracle中不能有null值,想对该语句进行处理,如果哪个参数是null的话,就针对某个对应的参数,将某个"= ?"替换为"is null"。请问代码应该如何实现。万分感谢。

String sql;
sql.replacAll("= null","is not null");

是不是可以这样操作。
String sql="codeselect count(*) from Cstcustom c, CstCustomManager cm where cm.customID = c.ID"
if(cm.userID )//判断有值
{
sql+=" and cm.userID = ? and cm.customID not in (select cm2.customID from CstCustomManager cm2 where cm2.userID = ?) "
}
if(c.sourceid)//判断有值
{
sql+=" and c.sourceid = ?"
}

这样做的条件是搜索结果与sql语句条件前后顺序没有关系,如果有关系,需要进行另外的讨论。

sql一般不都用拼接的吗.