2015-05-18 39 views
1

我試圖用java與orientdb數據庫連接。這樣 OrientGraph odb = new OrientGraph("plocal:C:/Users/USER/Desktop/orientdb/databases/testJ", "admin", "admin");如何使用java連接orientdb數據庫?

它顯示錯誤

HTTP Status 500 - Handler processing failed; nested exception is java.lang.NoClassDefFoundError: com/orientechnologies/orient/core/db/record/ODatabaseRecord

我的依賴..

<dependency> 
     <groupId>com.orientechnologies</groupId> 
     <artifactId>orientdb-core</artifactId> 
     <version>2.0.8</version> 
    </dependency> 
    <dependency> 
     <groupId>com.orientechnologies</groupId> 
     <artifactId>orientdb-jdbc</artifactId> 
     <version>1.7</version> 
    </dependency> 
    <dependency> 
     <groupId>com.tinkerpop</groupId> 
     <artifactId>pipes</artifactId> 
     <version>2.4.0</version> 
    </dependency> 
    <dependency> 
     <groupId>com.tinkerpop.blueprints</groupId> 
     <artifactId>blueprints-core</artifactId> 
     <version>2.4.0</version> 
    </dependency> 
    <dependency> 
     <groupId>com.tinkerpop.blueprints</groupId> 
     <artifactId>blueprints-orient-graph</artifactId> 
     <version>2.4.0</version> 
    </dependency> 

幫我糾正錯誤.. 預先感謝您

+0

嘗試'「file:/// Users/....」 – Thilo

+0

如果以正確的方式創建數據庫,此答案可能會有所幫助:http://stackoverflow.com/a/22893008/2841481和http: //stackoverflow.com/a/26846163/2841481 –

+0

'「file:/// Users/....」'不起作用。它顯示。 HTTP狀態500 - 請求處理失敗;嵌套的異常是com.orientechnologies.orient.core.exception.ODatabaseException:無法創建數據庫 –

回答

1

的ODatabaseRecord似乎從新版本被棄用。我對你的代碼進行了下列修改,並且它工作了(刪除了所有其他依賴項)。

POM

<dependency> 
    <groupId>com.orientechnologies</groupId> 
    <artifactId>orientdb-core</artifactId> 
    <version>2.0.8</version> 
</dependency> 
<dependency> 
    <groupId>com.orientechnologies</groupId> 
    <artifactId>orientdb-jdbc</artifactId> 
    <version>2.0.8</version> 
</dependency> 

Java代碼的

OrientGraphFactory ogf = new OrientGraphFactory(
      "plocal:C:/Users/USER/Desktop/orientdb/databases/testJ", "admin", "admin"); 
    OrientGraph og = ogf.getTx(); 

    try { 
     System.out.println("Features = " + og.getFeatures()); 
    } finally { 
     og.shutdown(); 
    } 

注:我發現線索here

+0

我使用你的代碼時遇到了問題。它只是不工作。我使用「root」「root」作爲登錄數據。你爲什麼使用管理員? –

+0

@FlorianNeiss我使用了'admin',因爲那是orientdb的默認用戶。查看詳情[here](http://orientdb.com/docs/2.0/orientdb.wiki/Security.html)。 – CuriousMind