用数字和中文可以进行模糊查询, 但是我输入中文后查不出结果。 在后台打印出来的执行语句放到数据库中查询可以查询出结果。 这是为什么?  
  奇怪的是以前都可以, 就是今天我的整个项目的查询输入中文都不可以了。 
   急需各位的解决方案!

解决方案 »

  1.   

      and a.user_name like '%李%'  这个怎么可能有错误类! 问题是我以前都可以啊, 就是今天不行, 我也是刚刚发现的, 而且我关机重启了也不行啊!
      

  2.   

    模糊查询要用PreparedStatement 而不要用 Statement
      还有, 你提的问题很烂, 很烂
      导致查不出结果有N种可能, 你要别人一个一个跟你说吗??
      所以..
      代码..
      代码..
      代码..
      

  3.   

    String user_no = request.getParameter("user_no");
    String user_name = request.getParameter("user_name");
    String user_status = request.getParameter("user_status");
    if (user_no == null)
    user_no = "";
    if (user_name == null)
    user_name = "";
    if (user_status == null)
    user_status = "1";
    Connection conn = null;
    Statement stmt = null;
    try {
    conn = DBPool.getPool().getConnection();
    stmt = conn.createStatement();
    String strSqlUserChar = "select a.user_id,a.user_name,a.user_no,a.user_pswd,a.exp_time,a.user_sex,a.char_id,a.user_status,a.user_tel,a.user_email,a.user_type,b.char_name from user_info a,char_info b where a.char_id=b.char_id and "
    + "a.user_no like '%"
    + user_no
    + "%' and a.user_name like '%"
    + StringUtil.UniToGb(user_name)
    + "%' and a.user_status="
    + user_status  
    + " group by a.user_id;";
    StringUtil.UniToGb(strSqlUserChar);
    System.out.print(strSqlUserChar);
    ResultSet userResultSet = stmt.executeQuery(strSqlUserChar);
    ArrayList userInfos = new ArrayList();
    while (userResultSet.next()) {
       你看代码哪里有错误, 以前一直是那样子的啊!
      

  4.   

     为什么以前可以,就今天不行类, URL不对,那个如何解决。
      

  5.   

    我是说你的 URL 是不是有 jdbc:mysql://localhost:3306/db2?autoReconnect=true&useUnicode=true&characterEncoding=utf8
    后面的几个参数
      

  6.   

    <Resource name="jdbc/hystation" auth="Container"
                  type="javax.sql.DataSource" 
      driverClassName="com.mysql.jdbc.Driver"
                  url="jdbc:mysql://127.0.0.1:3306/hystation?useUnicode=true"
                  username="root" password="admin" maxActive="20" maxIdle="10"
                  maxWait="-1"/> 我的是这样子的!
      

  7.   

    characterEncoding=utf8
    个加上试试。这两个参数应该一起用。
    还有,StringUtil.UniToGb(strSqlUserChar);这个方法不知道是什么,在这个方法前后把SQL打印出来看看。
      

  8.   

    把你的SQL贴出来看看,再试试查英文的字符能不能查出结果来。
      

  9.   

    useUnicode=true

    StringUtil.UniToGb(user_name)
    编码不一致吧?
      

  10.   

    select a.user_id,a.user_name,a.user_no,a.user_pswd,a.exp_time,a.user_sex,a.char_id,a.user_status,a.user_tel,a.user_email,a.user_type,b.char_name from user_info a,char_info b where a.char_id=b.char_id and a.user_no like '%%' and a.user_name like '%李%' and a.user_status=1 group by a.user_id;
     英文的和数字的都可以啊, 我数据库和工具的编码是GBK 
      

  11.   

      感谢   chouy 楼主。  
     正确答案是:
    url="jdbc:mysql://127.0.0.1:3306/hystation?autoReconnect=true&amp;useUnicode=true&amp;characterEncoding=utf8"