2 u014710016 u014710016 于 2016.01.14 19:46 提问

MySQL语句查询问题,异常和查询条件

源代码如下
switch (querryType) {
case 0:
hql = "from BookInfo b where b.bookName= '"+ querryKeys + "'''";
break;
case 1:
hql = "from BookInfo b where b.author='" + querryKeys + "'";
break;
case 2:
hql = "from BookInfo b where b.bookIsbn='" + querryKeys + "'";
break;
default:
hql = "from BookInfo b where b.bookName= '" + querryKeys +"'";
break;
}
很奇怪
使用http://localhost:8080/server/querry_book?querry_type=1&querry_keys=lvhaoyue
有查询结果如下
{"status":"200","message":"success","total":1,"result":[{"book_isbn":"13","book_name":"APP蓝图——Axure RP7.0移动互联网产品原型设计","author":"lvhaoyue"}]}
但是问题就是当我使用
http://localhost:8080/server/querry_book?querry_type=0&querry_keys=gongzhixiong查询时
报错如下
expecting ''', found '' [from org.yixing.entity.BookInfo b where b.bookName= gongzhixiong']; nested exception is org.hibernate.QueryException: expecting ''', found '' [from org.yixing.entity.BookInfo b where b.bookName= gongzhixiong']
在网找了半天也没办法解决,求解决。
另外就是当我改变查询条件当输入http://localhost:8080/server/querry_book?querry_type=0&querry_keys=小米时,返回成功但是result里面没有数据,不知道这个又怎么解决。

1个回答

devmiao
devmiao   Ds   Rxr 2016.01.14 20:00

hql = "from BookInfo b where b.bookName= '"+ querryKeys + "'''";
多了一个引号
hql = "from BookInfo b where b.bookName= '"+ querryKeys + "''";

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!