readDataFrame
Converts the result of an SQL query or SQL table (by name) to the DataFrame.
Note that if input dataframe contains duplicate column names, they will be automatically renamed in the resulting DataFrame.
Default Behavior:
If DbConnectionConfig.readOnly is true (which is the default), the connection will be:
explicitly set as read-only via
Connection.setReadOnly(true)used with
autoCommit = falseautomatically rolled back after reading, ensuring no changes to the database
Even if DbConnectionConfig.readOnly is set to false, the library still prevents data-modifying queries and only permits safe SELECT operations internally.
Return
the DataFrame containing the result of the SQL query.
Parameters
the SQL query to execute or the name of an SQL table.
the maximum number of rows to retrieve from the result of the SQL query execution. null (default) means no limit - all available rows will be fetched or positive integer (e.g., 100) - fetch at most that many rows
indicates how the column nullability should be inferred.
the type of database, could be a custom object, provided by user, optional, default is null, in that case the dbType will be recognized from the DbConnectionConfig.
controls SQL query validation when a query (not a table name) is provided. SqlValidation.ReadOnly blocks DDL/DML; SqlValidation.None (default) skips validation. Table name validation is always strict regardless of this parameter.
optional lambda to configure the PreparedStatement before execution. This allows for custom tuning of fetch size, query timeout, and other JDBC parameters.
Converts the result of an SQL query or SQL table (by name) to the DataFrame.
Note that if input dataframe contains duplicate column names, they will be automatically renamed in the resulting DataFrame.
Return
the DataFrame containing the result of the SQL query.
Parameters
the SQL query to execute or the name of an SQL table.
the maximum number of rows to retrieve from the result of the SQL query execution. null (default) means no limit - all available rows will be fetched or positive integer (e.g., 100) - fetch at most that many rows
indicates how the column nullability should be inferred.
the type of database, could be a custom object, provided by user, optional, default is null, in that case the dbType will be recognized from the Connection.
controls SQL query validation when a query (not a table name) is provided. SqlValidation.ReadOnly blocks DDL/DML; SqlValidation.None (default) skips validation. Table name validation is always strict regardless of this parameter.
optional lambda to configure the PreparedStatement before execution. This allows for custom tuning of fetch size, query timeout, and other JDBC parameters.
Converts the result of an SQL query or SQL table (by name) to the DataFrame.
Note that if input dataframe contains duplicate column names, they will be automatically renamed in the resulting DataFrame.
Example with HikariCP:
import com.zaxxer.hikari.HikariConfig
import com.zaxxer.hikari.HikariDataSource
val config = HikariConfig().apply {
jdbcUrl = "jdbc:postgresql://localhost:5432/mydb"
username = "user"
password = "password"
}
val dataSource = HikariDataSource(config)
// Read from a table
val customersDF = dataSource.readDataFrame("customers", limit = 100)
// Or execute a query
val queryDF = dataSource.readDataFrame("SELECT * FROM orders WHERE amount > 100")Return
the DataFrame containing the result of the SQL query.
Parameters
the SQL query to execute or the name of an SQL table.
the maximum number of rows to retrieve from the result of the SQL query execution. null (default) means no limit - all available rows will be fetched or positive integer (e.g., 100) - fetch at most that many rows
indicates how the column nullability should be inferred.
the type of database, could be a custom object, provided by user, optional, default is null, in that case the dbType will be recognized from the DataSource.
controls SQL query validation when a query (not a table name) is provided. SqlValidation.ReadOnly blocks DDL/DML; SqlValidation.None (default) skips validation. Table name validation is always strict regardless of this parameter.
optional lambda to configure the PreparedStatement before execution. This allows for custom tuning of fetch size, query timeout, and other JDBC parameters.
See also
Reads the data from a ResultSet and converts it into a DataFrame.
Note that if input dataframe contains duplicate column names, they will be automatically renamed in the resulting DataFrame.
A ResultSet object maintains a cursor pointing to its current row of data. By default, a ResultSet object is not updatable and has a cursor that can only move forward. Therefore, you can iterate through it only once, from the first row to the last row.
For more details, refer to the official Java documentation on ResultSet.
NOTE: Reading from the ResultSet could potentially change its state.
Return
the DataFrame generated from the ResultSet data.
Parameters
the type of database that the ResultSet belongs to.
the maximum number of rows to read from the ResultSet. null (default) means no limit - all available rows will be fetched or positive integer (e.g., 100) - fetch at most that many rows
indicates how the column nullability should be inferred.
See also
Reads the data from a ResultSet and converts it into a DataFrame.
Note that if input dataframe contains duplicate column names, they will be automatically renamed in the resulting DataFrame.
A ResultSet object maintains a cursor pointing to its current row of data. By default, a ResultSet object is not updatable and has a cursor that can only move forward. Therefore, you can iterate through it only once, from the first row to the last row.
For more details, refer to the official Java documentation on ResultSet.
NOTE: Reading from the ResultSet could potentially change its state.
Return
the DataFrame generated from the ResultSet data.
Parameters
the connection to the database (it's required to extract the database type) that the ResultSet belongs to.
the maximum number of rows to read from the ResultSet. null (default) means no limit - all available rows will be fetched or positive integer (e.g., 100) - fetch at most that many rows
indicates how the column nullability should be inferred.