java连接couchdb,如何将CouchDB与Java连接

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 doc = new HashMap();

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. But I am answering my best ignore if it not helps to you.

It seems you are not even opening the session by passing user login credentials.

Also you are directly trying to put Map object into DB create.

Session studentDbSession = new Session("localhost",5984);

Database studentCouchDb = studentDbSession.getDatabase("DBNAME");

Document newdoc = new Document();

Map properties = new HashMap();

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值