Orientdb Cant open Database from Java

2019-05-06 03:19发布

问题:

I created a database out of the orientdb console:

create database plocal:/C:/Development/orientdb/databases/testdb root root plocal graph

I started the server to make sure my database was created successfully. I opened the webinterface:

localhost:2480

And i logged in into testdb using root as user and root as password. Everything worked fine. But when i now want to connect to my database from Java-Code:

    OrientGraph graph = null;

    try {
        graph = new OrientGraph("plocal:C:/Development/orientdb/databases/testdb", "root", "root");

        System.out.println("success");
    } catch(OException e) {
        System.out.println("no success - " + e.getMessage());

        e.printStackTrace();
    } finally {
        if(graph != null) {
            graph.shutdown();
        }
    }

I get the following exception:

Exception in thread "main" com.orientechnologies.orient.core.exception.OSecurityAccessException: User or password not  valid for database: 'testdb'
at com.orientechnologies.orient.core.metadata.security.OSecurityShared.authenticate(OSecurityShared.java:150)
at com.orientechnologies.orient.core.metadata.security.OSecurityProxy.authenticate(OSecurityProxy.java:83)
at com.orientechnologies.orient.core.db.record.ODatabaseRecordAbstract.open(ODatabaseRecordAbstract.java:128)
at com.orientechnologies.orient.core.db.ODatabaseWrapperAbstract.open(ODatabaseWrapperAbstract.java:49)
at com.orientechnologies.orient.core.db.graph.OGraphDatabase.open(OGraphDatabase.java:92)
at de.hof.iisys.relationExtraction.freebase.tinkerpop.DAO.openGraph(DAO.java:30)
at de.hof.iisys.relationExtraction.freebase.main.Main.main(Main.java:44)

Why he is telling me that username or password is wrong when its not?

回答1:

In "create database" command from the console, user and password are used only to authenticate against a remote database. With "plocal", "local" and "memory" URL the admin user is always "admin" with password "admin".

So use:

graph = new OrientGraph("plocal:C:/Development/orientdb/databases/testdb", "admin", "admin");

Starting from OrientDB 1.7-SNAPSHOT the console accepts only the URL for such cases:

create database plocal:/C:/Development/orientdb/databases/testdb