Files
df-research/dataframe/docs/StardustDocs/topics/dataSources/sql/SQLite.md
2026-02-08 11:20:43 -10:00

1.9 KiB
Vendored
Raw Blame History

SQLite

Use Kotlin DataFrame to read data from SQLite databases with minimal setup via JDBC. Query and transform SQLite data directly in Kotlin using DataFrame and JDBC. Read SQLite tables into Kotlin DataFrame using the built-in JDBC integration.

Kotlin DataFrame supports reading from SQLite database using JDBC.

Requires the dataframe-jdbc module, which is included by default in the general dataframe artifact and in %use dataframe for Kotlin Notebook.

Youll also need SQLite JDBC driver:

dependencies {
    implementation("org.xerial:sqlite-jdbc:$version")
}
USE {
    dependencies("org.xerial:sqlite-jdbc:$version")
}

The actual Maven Central driver version could be found here.

Read

DataFrame can be loaded from a database in several ways:
a user can read data from a SQL table by given name (readSqlTable),
as a result of a user-defined SQL query (readSqlQuery),
or from a given ResultSet (readResultSet).
It is also possible to load all data from non-system tables, each into a separate DataFrame (readAllSqlTables).

See for more details.

import org.jetbrains.kotlinx.dataframe.io.DbConnectionConfig
import org.jetbrains.kotlinx.dataframe.api.*

val url = "jdbc:sqlite:testDatabase.db"

val dbConfig = DbConnectionConfig(url)

val tableName = "Customer"

val df = DataFrame.readSqlTable(dbConfig, tableName)