2017-08-04 28 views
0

我試圖連接到遠程orientdb連接枝條Java API的使用3.0平方米cersion OrientDB的時候讀響應超時。我已經安裝了Orientdb Ditribution orientdb社區空間,3.0.0m2,與demodb的。Orientdb 3.0m.02:在連接到遠程數據庫

的代碼是非常簡單的:

  orientDb = new OrientDB("remote:localhost", "root", "root", OrientDBConfig.defaultConfig()); 

     // open a session on the database 
     session = orientDb.open("demodb", "admin", "admin"); 

..投擲立刻異常:

java.io.IOException的:超時上在 com.orientechnologies.orient.client讀取響應。 (OChannelBinaryAsynchClient.java:249) at com.orientechnologies.orient.client.binary.OChannelBinaryAsynchClient.beginResponse(OChannelBinaryAsynchClient.java:176) 在 com.orientechnologies.orient.client.remote.OStorageRemote.openRemoteDatabase(OStorageRemote.java:1274) 在 com.orientechnologies.orient.client.remote.OStorageRemote.openRemoteDatabase(OStorageRemote.java:1309) 在 COM .orientechnologies.orient.client.remote.OStorageRemote.openRemoteDatabase在 com.orientechnologies.orient在 com.orientechnologies.orient.client.remote.OStorageRemote.open(OStorageRemote.java:392)(OStorageRemote.java:1254) .core.db.document.ODatabaseDocumentRemote.internalOpen(ODatabaseDocumentRemote.java:144) at com.orientechnologies.orient.core.db.OrientDBRemote.open(OrientDBRemote.java:82) 在 com.orientechnologies.orient.core.db.OrientDB.open(OrientDB.java:209) 在 com.orientechnologies.orient.core.db.OrientDB.open(OrientDB.java:194) 在 COM .activus.connectit.storage.graph.StorageGraphDb.dbSetup(StorageGraphDb.java:91)

這是一個錯誤還是濫用了Java API?

+0

你有chacked的java客戶端和服務器是完全相同的版本,通常這種情況發生時,之間存在未對齊服務器和客戶端 – tglman

回答

0

試試這個:

String DBname="db-name"; 
     String currentPath="remote:localhost/"+DBname; 

     OServerAdmin serverAdmin; 
     try 
     { 
      serverAdmin = new OServerAdmin(currentPath).connect("root", "root"); 
      if(serverAdmin.existsDatabase()) 
      { 

       OrientGraph g=new OrientGraph(currentPath); 

       // DO SOMETHING ... 

       g.shutdown(); 

      } 
      serverAdmin.close(); 
     } 
     catch (IOException e) 
     { 
      e.printStackTrace(); 
     } 

希望它可以幫助

問候

+0

很抱歉,但它不工作:我得到了「閱讀響應超時」 IOException異常.. –

+0

對不起,我忘了刷新的Eclipse下gradle這個項目是相同的,所以Java庫已經在3.0.0m1版本。 感謝您anwser –

0

我創建了一個小型的類用於測試兩種連接模式:

import java.io.IOException;  
import com.orientechnologies.orient.client.remote.OServerAdmin; 
import com.orientechnologies.orient.core.db.OrientDB; 
import com.orientechnologies.orient.core.db.OrientDBConfig; 
import com.orientechnologies.orient.core.db.document.ODatabaseDocument; 
import com.tinkerpop.blueprints.impls.orient.OrientGraph; 

/** 
* @author bsupiot 
* 
*/ 
public class OrientDBSimpleConnectionTest { 

    /** 
    * @param args 
    */ 
    public static void main(String[] args) { 
     // try connect with legacy tinkerpop 
     if (!connectWithTinkerpop()) { 

      // try with new unified interface 
      connectWithUnifiedInterface(); 
     } 
    } 

    /** 
    * connect with OrientDB 3.0 unified interface 
    */ 
    public static boolean connectWithUnifiedInterface() { 
     try { 
     // connect to remote database engine 
     OrientDB orientDb = new OrientDB("remote:localhost", "root", "root", 
     OrientDBConfig.defaultConfig()); 

     // open a session on the database 
     ODatabaseDocument session = orientDb.open("demodb", "admin", "admin"); 

     session.close(); 
     orientDb.close(); 

     // RUntime exception will be thrown if any problem has occured 
     return true; 
     } catch (Throwable ex) { 
      ex.printStackTrace(); 
      return false; 
     } 
    } 

    /** 
    * connect winth tinkerpop 
    */ 
    public static boolean connectWithTinkerpop() { 
     try { 
      // create a server adminitration 
      OServerAdmin serverAdmin = new 
      OServerAdmin("remote:localhost/demodb").connect("root", "root"); 
      // if the database already exists 
      if (serverAdmin.existsDatabase()) { 
       OrientGraph g = new OrientGraph("remote:localhost/demodb"); 
       System.out.println("connected: " + g); 
       g.shutdown(); 
       return true; 
      } else { 
       System.out.println("database does not exists"); 
       return false; 
      } 
     } catch (Throwable ex) { 
      ex.printStackTrace(); 
      return false; 
     } 
    } 

} 

The two functions throwsthe same exception. 
Noty that when Orientdb server is not started, I have (as excpected) a "connection refused" exception. 

Regards