0Pricing
Kotlin Academy · Lesson

Exposed Setup: Database Connection and Transaction DSL

Connect to a database, configure Exposed, and execute code inside transactions.

What Is Exposed?

Exposed is JetBrains' lightweight SQL framework for Kotlin. It offers two levels: a Query DSL (typesafe SQL expressions) and a DAO layer (Active Record-style entities). Both run inside explicit transactions.

Adding Exposed Dependencies

Add the core, JDBC driver bridge, and your database driver:

dependencies {
    implementation("org.jetbrains.exposed:exposed-core:0.52.0")
    implementation("org.jetbrains.exposed:exposed-jdbc:0.52.0")
    implementation("org.jetbrains.exposed:exposed-dao:0.52.0")
    implementation("com.h2database:h2:2.2.224") // or postgresql driver
    implementation("com.zaxxer:HikariCP:5.1.0")  // connection pooling
}

All lessons in this course

  1. Exposed Setup: Database Connection and Transaction DSL
  2. Defining Tables with the Table DSL
  3. CRUD with the Query DSL: insert, select, update, delete
  4. Exposed DAO: Entity Classes and Relationships
← Back to Kotlin Academy