我需要执行LIKE查询。我创建的代码如下:
AData ad : ao.find(AData.class, Query.select().where("user=? AND ISSUES LIKE %?%",user,issueId))) //issues field contain values as //"FIN-1,FIN-2,FIN7". issueId parameter has value as FIN-7它给出了以下错误:
java.sql.SQLException: Unexpected token: % in statement [SELECT * FROM PUBLIC.AO_0371A8_ADATA WHERE user=? AND ISSUES LIKE %?%]已将以下查询更新为:
AData ad : ao.find(AData.class, Query.select().where("user=? AND ISSUES LIKE '%? %'",user,issueId))) //issues field contain values as //"FIN-1,FIN-2,FIN7". issueId parameter has 值为FIN-7
它给出了下面的错误:(参数索引超出范围: 2) (也尝试了".......LIKE \'%?%\'"...但是给我同样的错误,如下:
com.atlassian.activeobjects.internal.ActiveObjectsSqlException: There was a SQL exception thrown by the Active Objects library:
Database:
- name:HSQL Database Engine
- version:1.8.0
- minor version:8
- major version:1
Driver:
- name:HSQL Database Engine Driver
- version:1.8.0
java.sql.SQLException: Invalid argument in JDBC call: parameter index out of range: 2
at com.atlassian.activeobjects.internal.EntityManagedActiveObjects.find(EntityManagedActiveObjects.java: 153)
at com.atlassian.activeobjects.osgi.DelegatingActiveObjects.find(DelegatingActiveObjects.java:81) <+3> (NativeMethodAccessorImpl.java:39) (DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
at org.springframework.osgi.service.importer.support.internal.aop.ServiceInvoker.doInvoke(ServiceInvoker.java:58)
at org.springframework.osgi.service.importer.support.internal.aop.ServiceInvoker.invoke(ServiceInvoker.j ava:62)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java: 171)
......
..
.当尝试以下查询时:
AData ad : ao.find(AData.class, Query.select().where("user=? AND ISSUES LIKE '%?%' ",user,issueId))) 还有其他的方式,
AData ad : ao.find(AData.class, Query.select().where("user=? AND ISSUES LIKE ? ",user, "%" +
issueId + "%"))) 在上述两种情况下,出现以下错误:(主要错误是,“java.sql.SQLException:无效参数在JDBC调用中:参数索引超出范围: 2")。
Uncaught exception thrown by REST service
com.atlassian.activeobjects.internal.ActiveObjectsSqlException: There was a SQL exception thrown by the Active Objects library:
Database:
- name:HSQL Database Engine
- version:1.8.0
- minor version:8
- major version:1
Driver:
- name:HSQL Database Engine Driver
- version:1.8.0
java.sql.SQLException: Invalid argument in JDBC call: parameter index out of range: 2
at com.atlassian.activeobjects.internal.EntityManagedActiveObjects.find(EntityManagedActiveObjects.java: 153)
at com.atlassian.activeobjects.osgi.DelegatingActiveObjects.find(DelegatingActiveObjects.java:81) <+3> (NativeMethodAccessorImpl.java:39) (DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
at org.springframework.osgi.service.importer.support.internal.aop.ServiceInvoker.do
....它是如何工作的..。这个LIKE查询出了什么问题?
谢谢
发布于 2013-05-24 23:28:47
更新: LIKE的参数是一个SQL字符串。在SQL中,对字符串使用单引号。
您可以用参数标记替换整个参数。
然后为两个参数提供值。第二个参数的值应该是可以包含通配符元素的字符串。这个例子看起来是正确的。
AData ad : ao.find(AData.class, Query.select().where("user=? AND ISSUES LIKE ?",user, "%" + issueId + "%"))) 发布于 2013-05-30 13:45:54
这是您在上面的代码中使用的类似SQL的语法:
where("user=? AND ISSUES LIKE %?%",user,issueId)只有在带引号的文字中或在提供的参数字符串中使用通配符时,通配符才有效。用法"LIKE %?%“无效。将其替换为:
ISSUES LIKE ?如果此语句的参数为'THO',则需要将其修改为'%THO%‘才能获得我认为您想要的通配符函数(例如:比如?将参数设置为'%THO%‘将匹配,尽管,深思熟虑和理解)。
https://stackoverflow.com/questions/16735161
复制相似问题