2015-04-02 47 views

回答

6

也許您正在尋找這樣的:

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

here


UPDATE:

在上面,如果數據庫已存在,將引發異常。 也許你會發現這些方法更有用:

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

小注:默認的用戶名/密碼將是「admin/admin」。可以在「config/orientdb-server-config.xm」下找到它。 – Vithushan 2015-04-06 08:27:04

相關問題