Orient DB - 使用密码创建 orient db 并检查是否可以使用 JAVA [英] Orient DB - create orient db with password and check if one available using JAVA

查看:51
本文介绍了Orient DB - 使用密码创建 orient db 并检查是否可以使用 JAVA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到我们可以使用以下方法创建 orient db:

I saw that we can create orient db using:

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

但是我们如何使用 REMOTE 类型的密码创建 orientDB 数据库.并检查数据库是否存在并说.或者如果找到它会覆盖吗?

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?

推荐答案

也许你正在寻找这个:

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

请参阅此处.

更新:

在上面,如果数据库已经存在,则会抛出异常.也许你会发现这些方法更有用:

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

这篇关于Orient DB - 使用密码创建 orient db 并检查是否可以使用 JAVA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆