简体   繁体   English

Javaouchdb4j DB连接

[英]Java couchdb4j DB connection

I'm using couchdb4j to establish a connection with couchDB. 我正在使用沙发床4j与沙发床建立连接。 It's working fine when im connecting to my local db, this is the code for that: 即时通讯连接到我的本地数据库时工作正常,这是该代码:

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

But i'm trying to get a connection with this site: stockquotetest.cloudant.com but it's not working, can anybody spot the problem? 但是我正在尝试与以下网站建立联系:stockquotetest.cloudant.com,但该网站无法正常工作,有人可以发现问题吗?

Session NewSession = new Session("stockquotetest.cloudant.com/", 5984, "user", "pass");

i'm getting this error: INFO: basic authentication scheme selected 我收到此错误:信息:选择基本身份验证方案

I also get this 我也得到这个

java.net.UnknownHostException: https
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at sun.security.ssl.SSLSocketImpl.connect(Unknown Source)
at sun.security.ssl.SSLSocketImpl.<init>(Unknown Source)
at sun.security.ssl.SSLSocketFactoryImpl.createSocket(Unknown Source)
at org.apache.commons.httpclient.protocol.SSLProtocolSocketFactory.createSocket(SSLProtocolSocketFactory.java:82)
at org.apache.commons.httpclient.protocol.SSLProtocolSocketFactory.createSocket(SSLProtocolSocketFactory.java:127)
at org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:707)
at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:387)
at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:323)
at com.fourspaces.couchdb.Session.http(Session.java:364)
at com.fourspaces.couchdb.Session.get(Session.java:325)
at com.fourspaces.couchdb.Session.getDatabaseNames(Session.java:167)
at CouchDBTest.ConnectDB(CouchDBTest.java:41)
at Home$4.actionPerformed(Home.java:166)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

when I run this line of code: 当我运行以下代码行时:

        Session NewSession = new Session("https://user:pass@stockquotetest.cloudant.com/", 80, true);

I reproduced this and ran into another issue before I got it working. 我转载了此内容,并在工作之前遇到了另一个问题。 First, the 6-parameter constructor for Session is what you're after: 首先,您需要使用Session6参数构造函数

public Session(String host, int port, String user, String pass, boolean usesAuth, boolean secure) {

In the example you gave above, this would work: 在您上面给出的示例中,这将起作用:

new Session("stockquotetest.cloudant.com", 443, "user", "pass", true, true);

This is because if you don't set secure to true, the URL will not be constructed with https . 这是因为,如果未将secure设置为true, 则不会使用https构造URL


After that was working, the next error was the Database class assuming that update_seq is an int . 在工作之后,下一个错误是Database类, 假设update_seq是一个int Cloudant will return a String update_seq , not an integer. Cloudant将返回字符串update_seq ,而不是整数。 I altered the field, response parsing, and getter in the Database class from int to String to make the code work for me. 我将Database类中的字段,响应解析和getter从int更改为String以使代码对我有用。

try this one ... make sure you are suing coucjdb4j lib for couchdb connection. 尝试这个...确保您使用coucjdb4j lib进行ouchdb连接。

Session studentDbSession = new Session("localhost", 5984); 会话studentDbSession = new Session(“ localhost”,5984);

Database studentCouchDb = studentDbSession.getDatabase("database_name"); 数据库studentCouchDb = studentDbSession.getDatabase(“ database_name”);

Hope this will help you. 希望这会帮助你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM