Java CouchDB Tutorial

Java CouchDB

To connect to the CouchDB with the Java Programming language, one can use the Ektorp library. It facilitates a persistence layer on top of the CouchDB. Follow the below steps to connect to the CouchDB with the Java Programming language and then to create a database.

  • Create a maven project.
  • Provide a name to your project.
  • Here, “couch-java” is the project name as well as the Artifact ID, “com.example” is the Group ID and “1.0-SNAPSHOT” is the version name.
  • Here, “” is the package name.
  • Now add the dependency in the “pom.xml” file.


Ektorp library dependency:







<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="" 



















Create a Java file for connection, after adding the dependency.

import org.ektorp.CouchDbConnector;
import org.ektorp.CouchDbInstance;
import org.ektorp.http.HttpClient;
import org.ektorp.http.StdHttpClient;
import org.ektorp.impl.StdCouchDbConnector;
import org.ektorp.impl.StdCouchDbInstance;
public class CouchJava {
public static void main(String[] args) throws MalformedURLException {
HttpClient httpClient = new StdHttpClient.Builder()
CouchDbInstance dbInstance = new StdCouchDbInstance(httpClient);
CouchDbConnector db = new StdCouchDbConnector("example", dbInstance);
DesignDocument dd = new DesignDocument("xyz");

Verify the CouchDB connection working, before executing the Java code.

  • Open the URL http://localhost:5984/_utils/.
  • All the available databases will thus be displayed.
  • Now to create a database, execute the Java code.
  • The database will thus be displayed in the database list.
  • Thus the database list in the CouchDB index web page now also includes a database named “example” that contains a document named “xyz”.



Content Protection by