我正在使用 spring mvc 和 hibernate 开发一个应用程序,当我想通过他的名字从数据库中选择一个对象时,我的 hql 查询遇到了问题。
因为名称中包含引号(ingénieur d'étude)
String hql = "From Intervenant I Where I.profil like '"+profil+"'";
我有这个异常(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']
是插入数据的用户,那么我如何知道用户插入了什么以及在哪里放置了引用或任何其他特殊字符?
请你帮帮我!
最佳答案
将单引号放在 mysql 中的转义字符中,如下所示
profile = ingénieur d''étude;
或者
profile = ingénieur d\'étude;
关于mysql - HQL 查询中的转义引号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24607972/