Java SDK N1QL not data return

query
n1ql

#1

Couchbase 4.5 + Java SDK 2.2.8

The query works couch base UI. I can got result return by ui/index.html#/query/workbench

My code:
// Connect to localhost
Cluster cluster = CouchbaseCluster.create(CouchbaseEnums.Couchbase_C3.getValue());
Bucket bucket = cluster.openBucket(“beer-sample”);

        // raw string query
 	N1qlQueryResult queryResult =
 			   bucket.query(N1qlQuery.simple("SELECT * FROM beer-sample LIMIT 10"));
 		
 	for(N1qlQueryRow row: queryResult){
 			System.out.println(row.value().toString());
 	}
 	
 	N1qlQueryResult query = bucket.query(select("*").from("beer-sample").limit(10));
    
	for(N1qlQueryRow row: query){
 			System.out.println(row.value().toString());
 	}
 	
    cluster.disconnect();
	
}

Log:
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/D:/.m2/raptor2/org/slf4j/slf4j-jdk14/1.7.7/slf4j-jdk14-1.7.7.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/D:/.m2/raptor2/com/ebay/dct/dctwsclient-with-dependencies/2.0.1/dctwsclient-with-dependencies-2.0.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.JDK14LoggerFactory]
Jul 27, 2016 2:59:42 PM com.couchbase.client.core.logging.Slf4JLogger info
INFO: CouchbaseEnvironment: {sslEnabled=false, sslKeystoreFile=‘null’, sslKeystorePassword=‘null’, queryEnabled=false, queryPort=8093, bootstrapHttpEnabled=true, bootstrapCarrierEnabled=true, bootstrapHttpDirectPort=8091, bootstrapHttpSslPort=18091, bootstrapCarrierDirectPort=11210, bootstrapCarrierSslPort=11207, ioPoolSize=24, computationPoolSize=24, responseBufferSize=16384, requestBufferSize=16384, kvServiceEndpoints=1, viewServiceEndpoints=1, queryServiceEndpoints=1, searchServiceEndpoints=1, ioPool=NioEventLoopGroup, coreScheduler=CoreScheduler, eventBus=DefaultEventBus, packageNameAndVersion=couchbase-java-client/2.2.8 (git: 2.2.8, core: 1.2.9), dcpEnabled=false, retryStrategy=BestEffort, maxRequestLifetime=75000, retryDelay=ExponentialDelay{growBy 1.0 MICROSECONDS, powers of 2; lower=100, upper=100000}, reconnectDelay=ExponentialDelay{growBy 1.0 MILLISECONDS, powers of 2; lower=32, upper=4096}, observeIntervalDelay=ExponentialDelay{growBy 1.0 MICROSECONDS, powers of 2; lower=10, upper=100000}, keepAliveInterval=30000, autoreleaseAfter=2000, bufferPoolingEnabled=true, tcpNodelayEnabled=true, mutationTokensEnabled=false, socketConnectTimeout=1000, dcpConnectionBufferSize=20971520, dcpConnectionBufferAckThreshold=0.2, dcpConnectionName=dcp/core-io, callbacksOnIoPool=false, queryTimeout=75000, viewTimeout=75000, kvTimeout=2500, connectTimeout=5000, disconnectTimeout=25000, dnsSrvEnabled=false}
Jul 27, 2016 2:59:43 PM com.couchbase.client.core.logging.Slf4JLogger info
INFO: Connected to Node couchbase-c3-7739.lvs01.dev.ebayc3.com
Jul 27, 2016 2:59:43 PM com.couchbase.client.core.logging.Slf4JLogger info
INFO: Opened bucket beer-sample
Jul 27, 2016 3:09:41 PM com.couchbase.client.core.logging.Slf4JLogger info
INFO: Closed bucket beer-sample
Jul 27, 2016 3:09:41 PM com.couchbase.client.core.logging.Slf4JLogger info
INFO: Disconnected from Node couchbase-c3-7739.lvs01.dev.ebayc3.com
Jul 27, 2016 3:09:41 PM com.couchbase.client.core.logging.Slf4JLogger info
INFO: Shutdown IoPool: success
Jul 27, 2016 3:09:41 PM com.couchbase.client.core.logging.Slf4JLogger info
INFO: Shutdown Core Scheduler: success
Jul 27, 2016 3:09:41 PM com.couchbase.client.core.logging.Slf4JLogger info
INFO: Shutdown Runtime Metrics Collector: success
Jul 27, 2016 3:09:41 PM com.couchbase.client.core.logging.Slf4JLogger info
INFO: Shutdown Latency Metrics Collector: success
Jul 27, 2016 3:09:43 PM com.couchbase.client.core.logging.Slf4JLogger info
INFO: Shutdown Netty: success


#2

The query method won’t usually throw exceptions but rather notify of execution errors into the N1qlQueryResult#errors() method.

One such execution error is malformed query, which notably occurs when the bucket’s name contains a dash “-” and is not escaped with backticks.

This is the case here. If in your statement you put backticks around “beer-sample” (and wrap it with Expression.i() in your second example: select("*").from(i("beer-sample")).limit(10)), it should work fine.