Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Unable to execute LIKE query in HSQLDB

dhaval soni
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 23, 2013

I need to execute LIKE query. i have created as below:

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

it gives me below error:

java.sql.SQLException: Unexpected token: % in statement [SELECT * FROM PUBLIC.AO_0371A8_ADATA WHERE user=? AND ISSUES LIKE %?%]

Updated the query below as :

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

gives me below error: ( parameter index out of range: 2) (Also tried as ".......LIKE \'%?%\'"... but give me same error as below:

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.java:62)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
......
..
.

How it could be working.. what is wrong in this LIKE query?

Thank You

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Timothy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 23, 2013

Have you tried this as described in the documentation?

entityManager.find(Post.class, Query.select().where("SOME_FIELD LIKE ?", "%" + arg));

https://developer.atlassian.com/display/DOCS/Finding+Entities

dhaval soni
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 26, 2013
Tried below both queries as riasing still error as follow:
AData ad : ao.find(AData.class, Query.select().where("user=? AND ISSUES LIKE ? ",user, "%" + issueId + "%")))

Also tried other way as below:

AData ad : ao.find(AData.class, Query.select().where("user=? AND ISSUES LIKE '%?%'  ",user,issueId)))

In above both cases, got below error: (Mainly error says, " java.sql.SQLException: Invalid argument in JDBC call: parameter index out of range: 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
    ....

I have passed both argumnet parameter and also gave two "?" though it raise and index out of range 2 error...

Harry Chan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 26, 2013

Are you sure it's ISSUES in caps? Case is important. Confirm that AData has these fields. What does this do?

AData ad : ao.find(AData.class, Query.select().where("user = ? AND ISSUES LIKE ?", user, "%" + issueId)))

TAGS
AUG Leaders

Atlassian Community Events