Home » Java CouchDB Example

Java CouchDB Example

by Online Tutorials Library

Java CouchDB Connectivity

We can connect to the CouchDB with the Java Programming language. To connect, we are using Ektorp library that provides a persistence layer on the top of CouchDB.

Here, we are explaining an example, in which we are connecting, creating database etc.

This example is created in NetBeans IDE 8.2.

First create a maven project and then follow the following steps.

CouchDB Java couchdb connectivity 1

Providing a name for our project.

CouchDB Java couchdb connectivity 2

After finishing, see, it has a pom.xml file. We need to add dependency in this file. let’s do it first.

// Ektorp library dependecy

// pom.xml

After adding dependency, create a Java file for connection. Our Java file contains the necessary connection code .

// JavaCouchDB.java

Our project looks like this:

CouchDB Java couchdb connectivity 3

Now before executing Java code, check the CouchDB connection is working or not. To check it follow this URL http://localhost:5984/_utils/. It will display all the available databases.

CouchDB Java couchdb connectivity 4

This screen-shot shows the CouchDB index web page.

Now, execute the Java code that will create a database. We can see that database in the databases list shown at the index web page.

CouchDB Java couchdb connectivity 5

Check the CouchDB index web page.

CouchDB Java couchdb connectivity 6

See, there is three databases including tutoraspire new one. It contains a document light shown as below.

CouchDB Java couchdb connectivity 7

Well, we have seen, how to connect and create database. Now, we can perform other database operations as well.

Next TopicPHP CouchDB

You may also like