2.3 KiB
Vendored
2.3 KiB
Vendored
Microsoft SQL Server (MS SQL)
Connect to Microsoft SQL Server using Kotlin DataFrame and JDBC — load structured data directly into your Kotlin workflow. Use Kotlin DataFrame to read from Microsoft SQL Server — run queries or load entire tables via JDBC. Fetch data from Microsoft SQL Server into Kotlin DataFrame using JDBC configuration.Kotlin DataFrame supports reading from Microsoft SQL Server (MS SQL) 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.
You’ll also need the official MS SQL JDBC driver:
dependencies {
implementation("com.microsoft.sqlserver:mssql-jdbc:$version")
}
USE {
dependencies("com.microsoft.sqlserver:mssql-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).
import org.jetbrains.kotlinx.dataframe.io.DbConnectionConfig
import org.jetbrains.kotlinx.dataframe.api.*
val url = "jdbc:sqlserver://localhost:1433;databaseName=testDatabase"
val username = "sa"
val password = "password"
val dbConfig = DbConnectionConfig(url, username, password)
val tableName = "Customer"
val df = DataFrame.readSqlTable(dbConfig, tableName)