2013-12-09 131 views
0

我正在使用couchdb4j與couchDB建立連接。它的正常工作時,即時通訊連接到我的本地數據庫,這是該代碼:Java couchdb4j數據庫連接

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

,但我試圖讓這個站點的連接:stockquotetest.cloudant.com但它不工作,任何人都可以發現問題?當我運行這行代碼選中基本身份驗證方案

我也得到這個

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) 

 Session NewSession = new Session("https://user:[email protected]/", 80, true); 
+0

,你必須在80端口連接(或https爲443) –

+0

嘿感謝您的幫助,但即時通訊STIL得到同樣的錯誤 \t \t會議newsession的=新會議(「stackis.cloudant.com/」,443,「 stackis「,」cloudant「); – user1959214

+0

什麼錯誤?您所說的INFO消息根本不是錯誤 –

回答

0

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

我得到這個錯誤:INFO我重現了這一點,並在我開始工作之前遇到了另一個問題。首先,6-parameter constructor for Session就是你追求:

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

在你上面給的例子,這會工作:

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

這是因爲如果你不設置secure爲真,URL will not be constructed with https


之後是工作,下一個錯誤是Databaseassuming that update_seq is an int。 Cloudant將返回一個字符串update_seq,而不是一個整數。我將Database類中的字段,響應解析和獲取方式從int更改爲String,以使代碼適用於我。

+0

從技術上講,* 6 *參數構造函數,而不是5. – Bdoserror

+0

@Bdoserror謝謝!更新 – sghill

0

試試這一個...確保你在couchdb4j庫中爲couchdb連接起訴。

Session studentDbSession = new Session(「localhost」,5984);

Database studentCouchDb = studentDbSession.getDatabase(「database_name」);

希望這會幫助你。