N1QL query returns result in query workbench but no result from code

H, I am using spring-data-couchbase to query couchbase. N1QL query return result in query workbench but no results in code

private static final String SIMPLE_QUERY = “SELECT * from $bucketName as d where d.nsid = $nsid”;

JsonObject pVal = JsonObject.create().put(“bucketName”, bucketName)
.put(“nsid”, NSID_DETAIL);

    N1qlQueryResult result = couchbaseBucket.query(N1qlQuery.parameterized(SIMPLE_QUERY, pVal));

@aqua123 Are you doing a parametrized query in the UI too? If not, can you try using a parametrized query in the UI. You can set the named parameters if you click on the “preferences” on the right side of the Query Workbench UI. Do you still get results from the UI?
Do you see any errors in the SDK logs?

1 Like

@aqua123 as far as I know the bucket name can not be parameterized. Can you try to only parameterize the part of the where clause and hardcode the bucket name?

You should also check the errors section of the java query result to make sure you got a non-error response from the server in the first place here.


@davids @daschl thanks for your replies. You are correct - bucket name can not be parametrized. Once I fixed that, it started working.