在HQL查询中转义引号 [英] Escape quote in HQL query
本文介绍了在HQL查询中转义引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在用spring mvc和hibernate开发一个应用程序,当我想通过他的名字从数据库中选择一个对象时,我在我的hql查询中遇到问题。
因为这个名字包含一个引号(ingénieurd'étude)
String hql =从Intervenant I where I.profil like'+ profil +';
我有这个例外:
org.springframework.web.util.NestedServletException:请求处理失败;嵌套异常是org.hibernate.QueryException:期待''',找到'< EOF>'[来自com.model.Intervenant I Where I.profil like'Ingénieurd'étude']
是插入数据的用户,所以我如何知道用户插入的内容以及它在哪里放置了引号或任何其他特殊字符? / p>
请帮助我!
解决方案
在mysql中的特性如下
profile =ingénieurd''étude;
OR
profile =ingénieurd\'étude;
I'm developping an application with spring mvc and hibernate, i have a problem in my hql query when i want to select an object from the database by his name.
Because the name contain a quote (ingénieur d'étude)
String hql = "From Intervenant I Where I.profil like '"+profil+"'";
i had this exception :
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.hibernate.QueryException: expecting ''', found '<EOF>' [From com.model.Intervenant I Where I.profil like 'Ingénieur d'étude']
Is the user who inserts datas, so how I can know what the user inserted and where it has put the quote or any other special caracters ?
Please can you help me !
解决方案
Put single quote to escaping charater in mysql like following
profile = ingénieur d''étude;
OR
profile = ingénieur d\'étude;
这篇关于在HQL查询中转义引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文