我是沙发基地的新手。我创建了自己的桶,没有密码保护。我想做一个选择查询。为此,我使用了N1Qlquery。我正在使用沙发基地的sdk2.2.6。当我查询它时,它能够连接到存储桶但无法查询。请帮忙。
这是我的代码
Bucket bucket=CouchbaseUtils.getBucketConnection("ProductLocation");
N1qlQueryResult queryResult;
Gson gson=new Gson();
List<Products> productsList=new ArrayList<Products>();
try{
queryResult=bucket.query(N1qlQuery.simple("SELECT * FROM "+bucket.name()+" where Location='"+location+"'"));
//queryResult=bucket.query(N1qlQuery.simple("SELECT * FROM "+bucket.name()));
}catch(Exception e){
System.out.println("The product which you are looking for is not present in that location");
e.printStackTrace();
return null;
}
Iterator<N1qlQueryRow> iterator=queryResult.allRows().iterator();
while(iterator.hasNext()){
productsList.add(new Gson().fromJson(CouchbaseUtils.stringToMap(iterator.next().toString()), Products.class));
}
return productsList;
这是输出
INFO: CouchbaseEnvironment: {sslEnabled=false, sslKeystoreFile='null', sslKeystorePassword='null', queryEnabled=true, queryPort=8093, bootstrapHttpEnabled=true, bootstrapCarrierEnabled=true, bootstrapHttpDirectPort=8091, bootstrapHttpSslPort=18091, bootstrapCarrierDirectPort=11210, bootstrapCarrierSslPort=11207, ioPoolSize=4, computationPoolSize=4, responseBufferSize=16384, requestBufferSize=16384, kvServiceEndpoints=1, viewServiceEndpoints=1, queryServiceEndpoints=1, searchServiceEndpoints=1, ioPool=NioEventLoopGroup, coreScheduler=CoreScheduler, eventBus=DefaultEventBus, packageNameAndVersion=couchbase-java-client/${project.version} (git: ${git.commit.id.describe}, core: ${git.commit.id.describe}), 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=10000, disconnectTimeout=25000, dnsSrvEnabled=false}
Jun 09, 2016 11:30:53 AM com.couchbase.client.core.node.CouchbaseNode signalConnected
INFO: Connected to Node localhost
Jun 09, 2016 11:30:54 AM com.couchbase.client.core.config.DefaultConfigurationProvider$8 call
INFO: Opened bucket ProductLocation
java.lang.RuntimeException: java.util.concurrent.TimeoutException
at com.couchbase.client.java.util.Blocking.blockForSingle(Blocking.java:75)
at com.couchbase.client.java.CouchbaseBucket.query(CouchbaseBucket.java:656)
at com.couchbase.client.java.CouchbaseBucket.query(CouchbaseBucket.java:582)
at com.tesco.productandlocation.daoImpl.ProductLocationDaoImpl.getProductByProductId(ProductLocationDaoImpl.java:50)
at TestMain.main(TestMain.java:29)
以下是按productId
查找产品的代码`List<Products> productsList=new ArrayList<Products>();
try{
queryResult=bucket.query(N1qlQuery.simple("SELECT * FROM "+bucket.name()+" where productid="+productid+""));
}catch(Exception e){
System.out.println("No product with that particular Id exists");
e.printStackTrace();
return null;
}
Iterator<N1qlQueryRow> iterator=queryResult.allRows().iterator();
while(iterator.hasNext()){
productsList.add(new Gson().fromJson(CouchbaseUtils.stringToMap(iterator.next().toString()), Products.class));
}
`
答案 0 :(得分:1)
您是否可以从cbq或web-console运行查询?
-Prasad