In Exposed, the Database class represents a database instance, and encapsulates the necessary connection details and configuration required to interact with a specific database.
Connecting to a Database
Every database access using Exposed is started by obtaining a connection and creating a transaction.
First of all, you have to tell Exposed how to connect to a database by using the Database.connect function. It won't create a real database connection but will only provide a descriptor for future usage.
A real connection will be instantiated later by calling the transaction lambda (see Transactions for more details).
Use the following to get a Database instance by simply providing connection parameters:
val db = Database.connect("jdbc:h2:mem:test", driver = "org.h2.Driver")
H2
In order to use H2, you need to add the H2 driver dependency:
By default, H2 closes the database when the last connection is closed. If you want to keep the database open, you can use the DB_CLOSE_DELAY=-1 option: