2017-08-04 88 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