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

How to create active object 'IN' condition query

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 15, 2013

my current query is as below and it works fine for single user:

ao.find(da.class, Query.select().where("user=?",user)

Now, i want to change this query to fetch multi users data as below , but it did not work and giving me invalid column name.

ao.find(da.class, Query.select().where("user IN (?)",user)

Also, tried by applying single qutoes. Even single user come in param value then also not worked and giving same error.

can any one suggest me whats wrong and have to correct here ?

error shows as below:

Caused by: java.sql.SQLException: Column not found: user in statement [SELECT * FROM PUBLIC.AO_0371A8_da WHERE "user" IN (?)]
	at org.hsqldb.jdbc.Util.throwError(Unknown Source)
	at org.hsqldb.jdbc.jdbcPreparedStatement.<init>(Unknown Source)
	at org.hsqldb.jdbc.jdbcConnection.prepareStatement(Unknown Source)
	at org.apache.tomcat.dbcp.dbcp.DelegatingConnection.prep

OR //when used "('?')" and verified for single user

at java.lang.Thread.run(Thread.java:662)
Caused by: java.sql.SQLException: Column not found: user in statement [SELECT * FROM PUBLIC.AO_0371A8_da WHERE "user" IN ('?')]
	at org.hsqldb.jdbc.Util.throwError(Unknown Source)
	at org.hsqldb.jdbc.jdbcPreparedStatement.<init>(Unknown Source)
	at org.hsqldb.jdbc.jdbcConnection.prepareStatement(Unknown Source)
	at org.apache.tomcat.dbcp.dbcp.DelegatingConnection.prepareStatement(DelegatingConnection.java:262)
.....

Thank You

3 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

2 votes
Answer accepted
Remo Siegwart
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 15, 2013

If you want to use IN queries, you need to construct the placeholder list yourself. Here is a snippet taken from: https://ecosystem.atlassian.net/browse/AO-263?focusedCommentId=69495&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-69495

MyEntity[] findEntities(Iterable<String> matchValues) {
    String placeholderCommaList = Joiner.on(", ").join(Iterables.transform(matchValues, Functions.constant("?")));
    Object[] matchValuesArray = Iterables.toArray(matchValues, Object.class);
    return ao.find(MyEntity.class, "primary_key_field_name", Query.select().where("match_field_name IN (" + placeholderCommaList + ")", matchValuesArray));
}

It's important, that the number of placeholders ("?") matches the number of arguments.

Hope this helps

0 votes
vsegura March 16, 2017

Hi,

Did you use Postgres database? Because, in this case, the user word is reserved for this database. If you want, you can apply the query on pgAdmin or something else and the result will be the same.

 

Regards.

0 votes
codelab expert
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 15, 2013
Please post the error message. What about concat using OR?
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 15, 2013

Updated original comment above.

ok, we can do through OR ..

it will be easy if i could use "IN" keyword...

TAGS
AUG Leaders

Atlassian Community Events