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();