问题描述
- hibernate操作mysql,模糊查询时中文查不到,数字和英文可以查到
-
用hibernate做模糊查询,页面传递参数也处理了乱码
@Action(value="searchNameByad")
public String searchNameByad()throws Exception{
System.out.println("android发送请求获取的参数是:"+buildingname);
//解决乱码问题
String bn = new String(buildingname.getBytes("iso-8859-1"),"UTF-8");
List buildings = buildingService.getByName(bn);
在本地测试传中文参数可以查到数据,但是在上传到服务器后,传递中文参数却查不到,只能数字、英文可以查询到结果。我用本地远程连接服务器数据库,也是中文参数查不到数据。。。在服务器上的数据库里操作查询也是可以查的到。。求解
这是本地远程连接服务器数据库后的hql语句
Hibernate: select building0_.buildingid as buildingid11_, building0_.area as area11_, building0_.buildingname as building3_11_, building0_.linkman as linkman11_, building0_.linkphone as linkphone11_, building0_.email as email11_, building0_.qrcode as qrcode11_, building0_.province as province11_, building0_.city as city11_ from airquality.building building0_ where building0_.buildingname like '%广%'
解决方案
加上编码格式试试
解决方案二:
<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/manager?characterEncoding=gbk"/>
解决方案四:
检查下你远程的数据库编码和本地的数据库编码格式是不是一样的啊?
时间: 2024-10-02 18:02:39