Orient DB - create orient db with password and check if one available using JAVA

a 夏天 提交于 2019-12-11 10:36:16

问题


I saw that we can create orient db using:

ODatabaseDocumentTx db2 = new ODatabaseDocumentTx ( "local:C:/temp/db/scratchpad" ).create();

But how can we create orientDB database using password with REMOTE type. And does that checks if a database exists and say. Or if found will it overwrite?


回答1:


Maybe you're looking for this:

void createDB(){
    new OServerAdmin("remote:localhost")
            .connect("root", "rootPassword")
            .createDatabase("databaseName", "graph", "plocal").close();
}

See here.


UPDATE:

In the above, if the database already exists, an exception will be thrown. Maybe you'll find these methods more useful:

private static final String dbUrl = "remote:localhost/databaseName";
private static final String dbUser = "root";
private static final String dbPassword = "rootPassword";

public static void createDBIfDoesNotExist() throws IOException {

    OServerAdmin server = new OServerAdmin(dbUrl).connect(dbUser, dbPassword);
    if (!server.existsDatabase("plocal")) {
        server.createDatabase("graph", "plocal");
    }
    server.close();
}

public static void dropDBIfExists() throws IOException {

    OServerAdmin server = new OServerAdmin(dbUrl).connect(dbUser, dbPassword);
    if (server.existsDatabase("plocal")) {
        server.dropDatabase("plocal");
    }
    server.close();
}


来源:https://stackoverflow.com/questions/29411525/orient-db-create-orient-db-with-password-and-check-if-one-available-using-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!