org.hibernate.QueryException: expecting ''', found '<EOF>' [SELECT DISTINCT D FROM XXX ]
原因就是有单引号,然后 sql语句加上 \' 转义字符。 或用 2个单引号。''
在hibernate的查询中不能用 \’ , 可以用'' 代替。
即:
'%"+StringEscapeUtils.escapeSql(_mediaName)+"%'
Open Declaration String org.apache.commons.lang.StringEscapeUtils.escapeSql(String str)
Escapes the characters in a String to be suitable to pass to an SQL query.
For example,
statement.executeQuery("SELECT * FROM MOVIES WHERE TITLE='" +
StringEscapeUtils.escapeSql("McHale's Navy") +
"'");
At present, this method only turns single-quotes into doubled single-quotes ("McHale's Navy" => "McHale''s Navy"). It does not handle the cases of percent (%) or underscore (_) for use in LIKE clauses.
see http://www.jguru.com/faq/view.jsp?EID=8881
Parameters:
str the string to escape, may be null
Returns:
a new String, escaped for SQL, null if null string input