Java API - OrientDB

This class provides a management environment between your application and the OrientDB Server.

Managing Servers

In order to operate on an OrientDB database, you first need to establish a connection with the server. You have two options in this: you can embed the server within your application using the OServer class or you can connect to a running server using this class. It can be found at com.orientechnologies.orient.core.db. For instance,

import com.orientechnologies.orient.core.db.OrientDB;

Once you've imported the class to your application, you can use one of the constructors to build a particular instance in your code.


This class provides two constructors to create instances of OrientDB in your application.

OrientDB(String url, OrientDBConfig config)

OrientDB(String url, String serverUser, 
      String serverPasswd, OrientDBConfig config)
  • url Defines the database URL, as a string. It supports embedded and remote URL's.
  • config Defines the database config, as an OrientDBConfig instance.
  • serverUser Defines the user name.
  • serverPasswd Defines the user password.


Using this class you can create a new OrientdDB instance in your application, which you can then use to operate on multiple databases on the connected server. This class supports two types of connections: embedded and remote. With embedded connections, you're connecting to an instance running on your current machine. With remote connections, you're using the remote port to connect to a server either running on localhost or a remote IP address.

For instance, creating a database on a remote host:

OrientDB orientdb = new OrientDB("remote:", "root", "root_passwd");
orientdb.create("musicdb", ODatabaseType.PLOCAL);
ODatabaseDocument session ="musicdb", "admin", "admin");


Alternatively, you could connect to an embedded host:

OrientDB orientdb = new OrientDB("embedded:./databases/", null, null);
orientdb.create("musicdb", ODatabaseType.MEMORY);
ODatabaseDocument session ="musicdb", "admin", "admin");



Once you've instantiated the class in your application, you can call the following methods on it to perform further operations.

Method Return Type Description
close() void Closes the current context with all related databases and pools.
create() void Creates a new database.
createIfNotExists() boolean Creates a new database if it doesn't exist.
drop() void Removes a database from the server.
exists() boolean Checks whether database exists.
list() List< String> Returns a list of databases on the server
open() ODatabaseDocument Opens and returns a Document database.

Closing Databases

When you've finished operating on a database or server, you can close the current context with all related databases and pools using the close() method. For instance,

OrientDB orientdb =  new OrientDB("embedded:/tmp/", OrientDBConfig.defaultConfig());

try(ODatabaseDocumentTx db ="test", "admin", "admin");) {

    // Enter your code here

} finally { 


results matching ""

    No results matching ""