[英]How to connect CouchDB with Java
I'm new about NOSQL. 我是NOSQL的新手。 I use couchDB and ektrop Java API.
我使用ouchDB和ektrop Java API。 I tried these code but it gives HTTP 405 error.
我尝试了这些代码,但出现HTTP 405错误。
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.
提前致谢。
I am also new to CouchDB/NoSQL. 我也是CouchDB / NoSQL的新手。 But I am answering my best ignore if it not helps to you.
但是我回答我最好不要理if,如果它对您没有帮助。
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 . 有关更多信息,您还可以参考使用Java Couchdb4j添加文档 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.