在HQL查询中转义引号

时间:2014-07-07 10:03:26

标签: mysql sql hibernate hql

我正在使用spring mvc和hibernate开发一个应用程序,当我想通过他的名字从数据库中选择一个对象时,我的hql查询有问题。

因为该名称包含引号(ingénieurd'étude)

String hql = "From Intervenant I Where I.profil like '"+profil+"'";

我有这个例外:

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']

是否是插入数据的用户,以便我如何知道用户插入的内容以及放置引号或任何其他特殊字符的位置?

请你能帮助我!

1 个答案:

答案 0 :(得分:2)

将单引号放入mysql中的转义字符,如下面的

profile = ingénieur d''étude;

OR

profile = ingénieur d\'étude;