如果String包含单引号或双引号,则调用CMIS Query时出错

时间:2016-01-22 06:34:03

标签: java liferay alfresco cmis

这是我的问题:当我尝试在包含单引号或双引号的CMIS查询中传递查询字符串时,它不会执行并产生如下错误:

06:19:23,306 ERROR [DispatcherPortlet:561] Could not complete request
org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException: Internal Server Error
at org.apache.chemistry.opencmis.client.bindings.spi.atompub.AbstractAtomPubService.convertStatusCode(AbstractAtomPubService.java:506)
at org.apache.chemistry.opencmis.client.bindings.spi.atompub.AbstractAtomPubService.post(AbstractAtomPubService.java:661)
at org.apache.chemistry.opencmis.client.bindings.spi.atompub.DiscoveryServiceImpl.query(DiscoveryServiceImpl.java:179)
at org.apache.chemistry.opencmis.client.runtime.SessionImpl$6.fetchPage(SessionImpl.java:935)
at org.apache.chemistry.opencmis.client.runtime.util.AbstractIterator.getCurrentPage(AbstractIterator.java:132)
at org.apache.chemistry.opencmis.client.runtime.util.AbstractIterator.getPageNumItems(AbstractIterator.java:57)
at org.apache.chemistry.opencmis.client.runtime.util.AbstractIterable.getPageNumItems(AbstractIterable.java:86)
at com.zeetv.util.UtilMethods.getQueryResults(UtilMethods.java:349)
at com.zeetv.action.twitter.TwitterController.checkTitle(TwitterController.java:121)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:175)
at org.springframework.web.portlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:369)
at org.springframework.web.portlet.mvc.annotation.AnnotationMethodHandlerAdapter.doHandle(AnnotationMethodHandlerAdapter.java:356)
at org.springframework.web.portlet.mvc.annotation.AnnotationMethodHandlerAdapter.handleResource(AnnotationMethodHandlerAdapter.java:302)
at org.springframework.web.portlet.DispatcherPortlet.doResourceService(DispatcherPortlet.java:859)
at org.springframework.web.portlet.FrameworkPortlet.processRequest(FrameworkPortlet.java:527)
at org.springframework.web.portlet.FrameworkPortlet.serveResource(FrameworkPortlet.java:479)

这是我的查询字符串:

select * from my:content where cmis:name Like 'test's new content1'

我也尝试过这样:

select * from my:content where cmis:name Like '"test's new content1"'

提前致谢。

1 个答案:

答案 0 :(得分:3)

请考虑审核this

  

字符串文字用单引号括起来。转义不会跟随SQL-92转义。字符串文字中的两个单引号不代表引号字符:''''不是单引号文字。

     

CMIS使用由上下文确定的可用转义字符定义基于反斜杠的转义。

     

'bob\'s' is used in place of 'bob''s'

     

SELECT * from cmis:document WHERE cmis:name = 'bob\'s'

     

基本逃避:

     
      
  • \\ represents \
  •   
  • \' represents '
  •   
     

...