Search icon
Subscription
0
Cart icon
Close icon
You have no products in your basket yet
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Couchbase Essentials

You're reading from  Couchbase Essentials

Product type Book
Published in Feb 2015
Publisher
ISBN-13 9781784394493
Pages 170 pages
Edition 1st Edition
Languages

Couchbase Java SDK


The Couchbase Java SDK is a purely Java-based library. It is a highly performant package with support for both synchronous and asynchronous operations. The most recent version contains support for Java 8 and earlier releases.

Current version

This SDK should be used for development against Couchbase Server versions ranging from 2.5 to 3.x. Version 1.2 of the SDK was developed to support the earlier versions of Couchbase Server.

How to obtain it

Java developers will most likely want to use Maven to add the Java SDK to their projects. The package is accessible from Maven Central:

<dependencies>
    <dependency>
        <groupId>com.couchbase.client</groupId>
        <artifactId>java-client</artifactId>
        <version>2.0.0</version>
    </dependency>
</dependencies>

Additionally, the SDK team publishes the Java binaries, which may be found at http://docs.couchbase.com/developer/java-2.0/download-links.html. The source code for the library is available on GitHub at https://github.com/couchbase/couchbase-java-client.

The basics

The following snippet demonstrates the basics of using the Couchbase Java SDK:

//Configure the cluster
CouchbaseCluster cluster = CouchbaseCluster.create("127.0.0.1");

//Open a bucket connection
Bucket bucket = cluster.openBucket("default");

//Create, and store a JSON document
JsonObject message = JsonObject.create().put("message", "The Hello, World!");
JsonDocument document = bucket.insert(JsonDocument.create("somekey", message));

//Read the document
JsonDocument savedMessage = bucket.get("somekey");

// Close the bucket connection
cluster.disconnect();
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}