Read from SQL databases

Edit page Last modified: 14 January 2025

These functions allow you to interact with an SQL database using a Kotlin DataFrame library.

There are two main blocks of available functionality:

  • Methods for reading data from a database

    • readSqlTable reads specific database table

    • readSqlQuery executes SQL query

    • readResultSet reads from created earlier ResultSet

    • readAllSqlTables reads all tables (all non-system tables)

  • Methods for reading table schemas

    • getSchemaForSqlTable for specific tables

    • getSchemaForSqlQuery for result of executing SQL queries

    • getSchemaForResultSet for created earlier ResultSet

    • getSchemaForAllSqlTables for all non-system tables

All methods above can be accessed like DataFrame.getSchemaFor...() via a companion for DataFrame.

Also, there are a few extension functions available on Connection, ResultSet, and DbConnectionConfig objects.

  • Methods for reading data from a database

    • readDataFrame on Connection or DbConnectionConfig converts the result of an SQL query or SQL table to a DataFrame object.

    • readDataFrame on ResultSet reads from created earlier ResultSet

  • Methods for reading table schemas from a database

    • getDataFrameSchema on Connection or DbConnectionConfig for an SQL query result or the SQL table

    • getDataFrameSchema on ResultSet for created earlier ResultSet

NOTE: This is an experimental module, and for now, we only support four databases: MS SQL, MariaDB, MySQL, PostgreSQL, and SQLite.

Moreover, since release 0.15 we support the possibility to register custom SQL database, read more in our guide.

Additionally, support for JSON and date-time types is limited. Please take this into consideration when using these functions.