Reputation: 39
I'm new about NOSQL. I use couchDB and ektrop Java API. I tried these code but it gives HTTP 405 error.
protected CouchDbInstance _db;
{
String dbname = "my_database";
try {
//creates a database with the specified name
CouchDbConnector dbc = _db.createConnector(dbname, true);
//create a simple doc to place into your new database
Map<String, Object> doc = new HashMap<String, Object>();
doc.put("_id", UUID.randomUUID().toString());
doc.put("season", "summer");
doc.put("climate", "arid");
dbc.create(doc);
} catch (Exception e) {
}
Examples on the internet are very complex for me, so I didn't understand anything and i did not find any tutorial, so i have two questions.
-How can i connect db ?
-How can i add/delete/update documents operations ?
If you give me examples codes, i will be really happy. Also you can suggest good tutorial. Thanks in advance.
Upvotes: 0
Views: 2511
Reputation: 1488
I am also new to CouchDB/NoSQL. But I am answering my best ignore if it not helps to you.
Session studentDbSession = new Session("localhost",5984);
Database studentCouchDb = studentDbSession.getDatabase("DBNAME");
Document newdoc = new Document();
Map<String , String> properties = new HashMap<String,String>();
properties.put(STUDENT_KEY_NAME, "REDDY");
properties.put(STUDENT_KEY_MARKS, "90");
properties.put(STUDENT_KEY_ROLL, "007");
newdoc.putAll(properties);
studentCouchDb.saveDocument(newdoc);
For more information you can also refer Adding Document Using Java Couchdb4j.
Upvotes: 1