高手来!!!!急急急!!!!!
我做了一个站内搜索,用的是mysql数据库.当在关键字文本框中输入字符的时候可以查询出结果,输入中文的时候却查不出来.我输入了sql语句,在数据库查询可以得到结果,请问如何解决
[解决办法]
text中的变量传递给sql的时候是否正确.
[解决办法]
典型编码问题,text框传出来的是ISO-8859-1的编码,到SQL里要给它重新以GBK编码
String string=new String(tempString.getBytes( "ISO-8859-1 "), "GBK ");
[解决办法]
可能传入到数据库查询的中文是乱码,你输出sql语句看下
[解决办法]
要把SQL的WHERE拼成这样才能查出来
function searchStr()
{
var s1= "infoName ";
var s2= "infoId ";
var s3= "str2 ";
var s4= "infoType ";
var s5= "infoDescription ";
var s6= "infoValue ";
var final= "groupinnerid= ' <%=id%> ' ";
var str= " ";
if(document.all[s1].value!= " ")
{
str = s1 + " like '% "+ document.all[s1].value + "% ' " + " and ";
}
if(document.all[s2].value!= " ")
{
str = str +s2 + " like '% " + document.all[s2].value + "% ' " + " and ";
}
if(document.all[s3].value!= " ")
{
str = str +s3 + " like '% " + document.all[s3].value + "% ' " + " and ";
}
if(document.all[s4].value!= " ")
{
str = str +s4 + " like '% " + document.all[s4].value + "% ' " + " and ";
}
if(document.all[s5].value!= " ")
{
str = str +s5 + " like '% " + document.all[s5].value + "% ' " + " and ";
}
if(document.all[s6].value!= " ")
{
str = str +s6 + " like '% " + document.all[s6].value + "% ' " + " and ";
}
str=str+final;
//alert(str);
document.all[ "whereStr "].value=str;
document.all[ "currentPage "].value= "1 ";
document.forms[0].action= "ListDeployinfo.jsp ";
document.forms[0].submit();
}
[解决办法]
把search的sql语句打出来看看,是不是编码问题,
[解决办法]
代码 发出来看看 只要FROM表单 和 SQL语句那部分
[解决办法]
应该还是编码问题,要看你的mysql用的是什么编码,一般来说只要用什么编码写入数据库的还用什么编码去查就能查出来.