急救!在使用ibatis+struts2写模糊查询时,报错

u011955534 2013-12-21 06:58:07
配置文件:
<select id="getGoodsByKeyword" resultClass="goods" parameterClass="string">
select * from goods where goodName like concat('%',#goodName#,'%')
</select>

异常:
com.ibatis.common.jdbc.exception.NestedSQLException:   
--- The error occurred in com/dcst/imicai/bean/goods.xml.
--- The error occurred while applying a parameter map.
--- Check the getGoodsByKeyword-InlineParameterMap.
--- Check the statement (query failed).
--- Cause: java.sql.SQLException: Illegal mix of collations (gb2312_chinese_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation 'like'
...全文
193 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
长笛党希望 2013-12-22
  • 打赏
  • 举报
回复
楼主尝试吧goodName的值打印出来试试,看看是不是乱码。。 另外为了统一字符,可以把链接数据库的url写成这样: jdbc:mysql://localhost:3306/dbname?useUnicode=true&characterEncoding=UTF8
  • 打赏
  • 举报
回复
这个异常信息告诉你,编码不一样,无法进行模糊比较。首要问题还是要把编码格式统一。
u011955534 2013-12-22
  • 打赏
  • 举报
回复
引用 1 楼 defonds 的回复:
你换成 UTF-8 字符集试试。 以 MySQL 为例,连接 URL 这样写jdbc:mysql://localhost:3306/testdb?characterEncoding=utf8 数据库 ,CHARSET=utf8,Collation = utf8_general_ci
是编码格式问题,搞定了,谢谢
Defonds 2013-12-22
  • 打赏
  • 举报
回复
你换成 UTF-8 字符集试试。
以 MySQL 为例,连接 URL 这样写jdbc:mysql://localhost:3306/testdb?characterEncoding=utf8
数据库 ,CHARSET=utf8,Collation = utf8_general_ci

81,095

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧