A Java application connects to the database (creates a database handle) by instantiating a Connection. The database must have been previously created by calling the Database method
, possibly in a different process if the database is in shared memory. If successful, the constructor returns a database connection that is used in subsequent calls to database operations, particularly the transaction control functions.
open()
Note that all applications must create a separate connection for each thread (task) that accesses the database; database connections cannot be shared between different threads or tasks.
Applications should disconnect from the database once the database connection is no longer needed to allow the database runtime to “de-allocate” internal memory used to maintain the connection. A Java application disconnects from the database by calling the Connection method
disconnect()
. The database cannot be destroyed (closed) until all active connections are closed.Example
Typical application code to connect to an in-memory database could look like the following:
static final int DATABASE_SIZE = 16*1024*1024; public static void main(String[] args) { Database db = new Database(); Database.Parameters params = new Database.Parameters(); ... params.memPageSize = 128; // Memory page size params.classes = new Class[] { Record.class }; // List of classes that will be stored in eXremeDB database. db.open("operations-db", params, DATABASE_SIZE); Connection con = new Connection(db); ... // Perform database operations ... con.disconnect(); db.close(); }