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:
/*
* Copyright (c) 2016 Couchbase, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.couchbase.client.java.query;
import com.couchbase.client.java.document.json.JsonArray;
import com.couchbase.client.java.document.json.JsonObject;
This file has been truncated. show original
Thank you Keshav it really helps me