项目救急啊
需求有String str[] =new String[list.size];存放的是sql的查询条件
比如是String str={a,b,c,d,e};要求的比较条件是 a=b and a=c and a=d and a=e
and b=c and b=d and b=e
and c=d and c=e
and d=e
这只是其中一种条件,因为数组里面的内容是动态的,有高手希望不惜赐教啊,给写个动态生成的代码 小弟在这里感谢大家了。
需求有String str[] =new String[list.size];存放的是sql的查询条件
比如是String str={a,b,c,d,e};要求的比较条件是 a=b and a=c and a=d and a=e
and b=c and b=d and b=e
and c=d and c=e
and d=e
这只是其中一种条件,因为数组里面的内容是动态的,有高手希望不惜赐教啊,给写个动态生成的代码 小弟在这里感谢大家了。
解决方案 »
- webservice+xml
- Struts2 拦截器 如何得到action中的参数
- Oracle数据库查询问题???求高手帮忙
- ASP与JSP程序共用80端口
- 关于Java的深入学习~~~~~~
- hibernate.cfg.xml
- javax.ejb.EJBException: Transaction aborted; nested exception is: javax.transaction.RollbackException: Transaction marked for ro
- 关于Hibernate事务
- 帮帮忙,谈谈weblogic与websphere,jbuilder与WSAD的差别(提供网址也可),多谢~~
- 先来的两个有分:)
- hibernate注解问题
- JAVA程序内存泄露问题
and b=c and b=d and b=e
and c=d and c=e
and d=e
你这个条件 这样写 a=b and a=c and a=d and a=e 这样就能判断他们都相等了吧?还有就是 你的条件 在list里面放着,怎么还重新放到数组里呢?在list里面不行吗?
and b=c and b=d and b=e
and c=d and c=e
and d=e这个不就是
a=b=c=d=e吗?
public String getWhereCondition(String[] conditions){
String result = "":
int arrLenth = conditions.length
for(int i = 0; i < arrLenth ; i++){
for(int j = i + 1; j < arrLenth ;j++){
if(!result.equals("")) result += " and ";
result += (conditions[i] + " = " + conditions[j]);
}
}
return result;
}
看看满足需求不?
就可以知道
and b=c and b=d and b=e
and c=d and c=e
and d=e
你要做的就是遍历数组,把条件用and拼出 a=b and a=c and a=d and a=e 。