How to create Dynamic where clause using N1QL in JAVA

select a.function_section.* from supplier_function where a.type = “FUNCTION” this is working correctly

String function = "FUNCTION"
select a.function_section.* from supplier_function where a.type = $function this is not returning any results
function variable will get populated with some values dynamically
which I want to pass into my N1QL in JAVA.

Thanks in Advance for you help

you can use PREPARED statement and query data via REST API,like

# Create PREPARE statement
curl -v http://127.0.0.1:8093/query/service --data-urlencode 'statement=PREPARE queryAllByType FROM select a.function_section.* from supplier_function a where a.type =$funtion; '
# query by PREPARE from client(JAVA)
curl -v http://127.0.0.1:8093/query/service -d 'prepared="queryAllByType"&$funtion="FUNCTION"'


Also, using Java SDK:

https://developer.couchbase.com/documentation/server/4.1/sdks/dotnet-2.2/prepared-statements.html
http://docs.couchbase.com/sdk-api/couchbase-java-client-2.3.0/com/couchbase/client/java/query/N1qlQuery.html

Example for named parameter:

Thank you Keshav it really helps me