Reputation: 513
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?
Upvotes: 1
Views: 1350
Reputation: 1579
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();
}
Upvotes: 6