当查询某一个字符串中包含有" ' "字符时,会出现异常
异常代码:
Exception in thread "main" org.springframework.orm.hibernate3.HibernateQueryException: expecting ''', found '<EOF>' [from com.jy.vo.Ndg n where n.jobNum=153 and n.url ='http://chinese.wsj.com/gb/20081028/ecm114937.asp?camp=globe'']; nested exception is org.hibernate.QueryException: expecting ''', found '' [from com.jy.vo.Ndg n where n.jobNum=153 and n.url =''']
Caused by: org.hibernate.QueryException: expecting ''', found '<EOF>' [from com.jy.vo.Ndg n where n.jobNum=153 and n.url ='http://chinese.wsj.com/gb/20081028/ecm114937.asp?camp=globe'']
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:204) at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:111) at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:77) at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:56) at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:72) at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133) at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112) at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1623) at org.springframework.orm.hibernate3.HibernateTemplate$29.doInHibernate(HibernateTemplate.java:832) at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:362) at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:830) at org.springframework.orm.hibernate3.HibernateTemplate.find阿(HibernateTemplate.java:822)
|
出错分析:
因为字符串包含了数据库查询默认的结束字符段" ' ",数据库认为这是字符串结尾的字符,但实际上不是,数据库查询语句就会多出一个字符" ' ",所以使用hibernate查询时就会返回EOF异常
解决方法:
使用replace把" ' "替代为 " '' "
阅读(4165) | 评论(0) | 转发(0) |