1

私はカウチベースが初めてです。パスワードで保護されていない独自のバケットを作成しました。選択クエリを実行したい。そのために、N1Qlquery を使用しました。私はcouchbaseの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));
    }
    `
4

1 に答える 1