mysql like 查询 有单引号的处理办法。org.hibernate.QueryException: expecting ''', found '<EOF>' [SELECT DISTINCT

来源:互联网 发布:咖啡厅收银软件 编辑:程序博客网 时间:2024/06/05 14:20

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=8881Parameters:str the string to escape, may be nullReturns:a new String, escaped for SQL, null if null string input


0 0