Search code examples
javadatabaseorientdb

How to connect orientdb database using java?


I tried to connect using orientdb database with java. like this OrientGraph odb = new OrientGraph("plocal:C:/Users/USER/Desktop/orientdb/databases/testJ", "admin", "admin");

Its showing an error

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

My dependencies..

    <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>

help me to resolve the error.. thank you in advance


Solution

  • The ODatabaseRecord seems to be deprecated from new version. I made following changes to your code and it worked (remove all other dependencies).

    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 Code

    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();
        }
    

    Note: I found clue here.