When am trying to connect couch db from java ,am getting following error?

When am trying to connect couch db from java ,am getting following error ?

05-08 07:02:01.310 2608-2646/android.com.eventdriven E/CouchbaseLite/REPLICATOR: {Repl#3} Got LiteCore error: POSIX error 111 “Connection refused”
05-08 07:02:01.431 2608-2608/android.com.eventdriven I/MyActivity: Error code :: 111

Do you really mean CouchDB, as in the Apache CouchDB project? That is not affiliated with Couchbase and is no longer supported in version 2.0+ of Couchbase Lite.

Hi Borrrden,

I have installed sync gateway and couchbase server. Its running in browser
for Eg : if i hit http://localhost:4984/dhaya/ am getting following as output
{“committed_update_seq”:1,“compact_running”:false,“db_name”:“dhaya”,“disk_format_version”:0,“instance_start_time”:1557294861780948,“purge_seq”:0,“state”:“Online”,“update_seq”:1}

Also am using following lines of code in android ,it’s showing above error .

// Get the database (and create it if it doesn’t exist).
DatabaseConfiguration config = new DatabaseConfiguration(getApplicationContext());
Database database = null;
try {
database = new Database(“dhaya”, config);
} catch (CouchbaseLiteException e) {
e.printStackTrace();
}

// Create a new document (i.e. a record) in the database.
MutableDocument mutableDoc = new MutableDocument()
.setFloat(“version”, 2.0F)
.setString(“type”, “SDK”);

// Save it to the database.
try {
database.save(mutableDoc);
} catch (CouchbaseLiteException e) {
e.printStackTrace();
}

// Update a document.
mutableDoc = database.getDocument(mutableDoc.getId()).toMutable();
mutableDoc.setString(“language”, “Java”);
try {
database.save(mutableDoc);
} catch (CouchbaseLiteException e) {
e.printStackTrace();
}
Document document = database.getDocument(mutableDoc.getId());
// Log the document ID (generated by the database) and properties
Log.i(TAG, "Document ID :: " + document.getId());
Log.i(TAG, "Learning " + document.getString(“language”));

// Create a query to fetch documents of type SDK.
Query query = QueryBuilder.select(SelectResult.all())
.from(DataSource.database(database))
.where(Expression.property(“type”).equalTo(Expression.string(“SDK”)));
ResultSet result = null;
try {
result = query.execute();
} catch (CouchbaseLiteException e) {
e.printStackTrace();
}
Log.i(TAG, "Number of rows :: " + result.allResults().size());

// Create replicators to push and pull changes to and from the cloud.
Endpoint targetEndpoint = null;
try {
targetEndpoint = new URLEndpoint(new URI(“ws://127.0.0.1:8091/dhaya”));
} catch (URISyntaxException e) {
e.printStackTrace();
}
ReplicatorConfiguration replConfig = new ReplicatorConfiguration(database, targetEndpoint);
replConfig.setReplicatorType(ReplicatorConfiguration.ReplicatorType.PUSH_AND_PULL);

// Add authentication.
replConfig.setAuthenticator(new BasicAuthenticator(“dhaya”, “dhaya123”));

// Create replicator.
Replicator replicator = new Replicator(replConfig);

// Listen to replicator change events.
replicator.addChangeListener(new ReplicatorChangeListener() {
@Override
public void changed(ReplicatorChange change) {
if (change.getStatus().getError() != null)
Log.i(TAG, "Error code :: " + change.getStatus().getError().getCode());
}
});

// Start replication.
replicator.start();
}

The problem is you are not pointing CBL at Sync Gateway.

To be more precise: Port 8091 is Couchbase Server itself, not Sync Gateway. Couchbase Lite cannot communicate directly with Couchbase Server, and in any real installation the Server will be behind a firewall for security reasons.