关于JSP的一个查询问题???

来源:百度知道 编辑:UC知道 时间:2024/09/28 10:35:50
查询商品的时候
select * from products where cname like '%'"+传过来的参数+"'' order by cid desc

比如服饰名叫 "最流行最酷的服饰" 参数为服饰 能查询出来

可是当参数为 酷 流行 的时候就查不到 问一下为什么

还是有更好的sql 语句 自己就是用得模糊查询
不是的 我就是一个一个输入的 也查询不到

如果,你觉得程序都没错的话,那你看看是不是乱码的问题,因为你传的是中文,有可能是乱码!还有建议你不要select * from products where cname like '%'"+传过来的参数+"'' order by cid desc 这样写SQL语句,而是用占位符:select * from products where cname like ? order by cid desc .如果你用的是hibernate,select * from products where cname like '%'"+传过来的参数+"'' order by cid desc这样传中文参数,100%是会出乱码问题的

单个的话这样应该木有问题了

select * from products where cname like '%"+传过来的参数+"%' order by cid desc

StringTokenizer fenxi = new StringTokenizer(s, " ")
先用StringTokenizer如何?

然后做个判断
while (fenxi.hasMoreTokens()) {
String temp = fenxi.nextToken();
try {
a[i] = Double.valueOf(temp).doubleValue();
i++;
} catch (NumberFormatException e) {
}
}

这样来将“ ”(空格)作为关键字的区分点。

后面在加一个'%'