Create a Database


Three simple steps:

  1. Stablish connection with CouchDB server. Just need to invoke ServerImpl with IP address and the port number. One important limitation is that if you have some sort of proxy or load balancer (other than CouchDB itself) you cannot: it is not possible providing a URL instead of the dupla (IP, PORT).
  2. Create the Database by invoking createDatabase with the name of the Database as String. Additionally, you might check if it already exists by getting the list of existing Databases (uselistDatabases).
  3. Get a reference to the Database object.
    // Access server implementation
    server = new ServerImpl(ip, port);

    DataBase if it does not exist
    if (!server.listDatabases().contains(dbName)) {
        if (!server.createDatabase(dbName)) {
            throw new Exception("Failed to create database");
        }
    }

    // Get access to the database
    Database db = new Database(server, dbName);

IMPORTANT: CouchDB Database name cannot contain uppercase characters! Only lowercase characters (a-z), digits (0-9), and any of the characters _, $, (, ), +, -, and / are allowed. And must begin with a letter.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s