javacouchdbektorp

Ektorp CouchDB test connection


I'm working on a Java application which uses the Ektorp Framework to communicate with a CouchDB. I use the following code to create a new CouchDbInstance:

HttpClient httpClient = new StdHttpClient.Builder()
    .host("localhost")
    .port("5984")
    .username("")
    .password("");

/* no user name and password required because, its admin party */

CouchDbInstance couchDbInstance = new StdCouchDbInstance(httpClient);

Now I want to test the connection to the CouchDB before I create/modify etc. documents. There is no method for testing the connection. Do you have a tip for me?


Solution

  • I'm using Ektorp in my current project and we're testing this with couchDbConnector.getAllDatabases(), catching DbAccessExceptions.

    This has the slight advantage over checkIfDbExists() of being totally agnostic of the actual databases configured on the CouchDB server, and not referencing any application-specific configuration for connection checking just feels a little cleaner.