如何将CouchDB与Java连接 [英] How to connect CouchDB with Java

查看:195
本文介绍了如何将CouchDB与Java连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对NOSQL还是陌生的.我使用ouchDB和ektrop Java API.我尝试了这些代码,但出现HTTP 405错误.

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.

推荐答案

我还是CouchDB/NoSQL的新手.但是,如果对您没有帮助,我会回答我最好的无视.

I am also new to CouchDB/NoSQL. But I am answering my best ignore if it not helps to you.

  1. 似乎您甚至都没有通过传递用户登录凭据来打开会话.
  2. 您还直接尝试将Map对象放入数据库创建中.

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); 

有关更多信息,您还可以参考使用Java Couchdb4j添加文档.

For more information you can also refer Adding Document Using Java Couchdb4j.

这篇关于如何将CouchDB与Java连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆