Learn R Programming

DatabaseConnector

DatabaseConnector is part of HADES.

Introduction

This R package provides function for connecting to various DBMSs. Together with the SqlRender package, the main goal of DatabaseConnector is to provide a uniform interface across database platforms: the same code should run and produce equivalent results, regardless of the database back end.

Features

  • Create connections to the various database platforms:
    • MicrosoftSQL Server
    • Oracle
    • PostgresSql
    • Microsoft Parallel Data Warehouse (a.k.a. Analytics Platform System)
    • Amazon Redshift
    • Google BigQuery
    • SQLite
    • Spark
    • InterSystems IRIS
  • Statements for executing queries with
    • Error reporting to file
    • Progress reporting
    • Multiple statements per query
  • Support for fetching data to Andromeda objects
  • Insert data frame to a database table, using bulk loading if appropriate environmental variables are set.
  • Supports the DBI interface.
  • Supports the dbplyr interface.
  • Integrates with RStudio's Connections tab

Examples

connectionDetails <- createConnectionDetails(dbms="postgresql", 
                                             server="localhost",
                                             user="root",
                                             password="blah")
conn <- connect(connectionDetails)
querySql(conn,"SELECT COUNT(*) FROM person")
disconnect(conn)

Technology

DatabaseConnector is an R package using Java's JDBC drivers and other DBI drivers.

System Requirements

Running the package requires R with the package rJava installed. Most of the JDBC drivers will run on Java >= 8. However, some drivers (e.g. Spark / DataBricks) will require a higher Java version. We recommend running Java 21, which is the version used in our continuous integration.

Installation

  1. See the instructions here for configuring your R environment, including Java.

  2. To install the latest stable version, install from CRAN:

install.packages("DatabaseConnector")
  1. Download the database drivers as described here.

  2. (Optionally) To use Windows Authentication for SQL Server, download the authentication DDL file as described here.

User Documentation

Documentation can be found on the package website.

PDF versions of the documentation are also available:

Support

  • Developer questions/comments/feedback: OHDSI Forum
  • We use the GitHub issue tracker for all bugs/issues/enhancements

Contributing

Read here how you can contribute to this package.

License

DatabaseConnector is licensed under Apache License 2.0. The JDBC drivers fall under their own respective licenses.

Development

DatabaseConnector is being developed in R Studio.

Development status

Stable. The code is actively being used in several projects.

Acknowledgements

  • This project is supported in part through the National Science Foundation grant IIS 1251151.

Copy Link

Version

Install

install.packages('DatabaseConnector')

Monthly Downloads

3,474

Version

8.0.0

License

Apache License

Issues

Pull Requests

Stars

Forks

Maintainer

Martijn Schuemie

Last Published

October 1st, 2026

Functions in DatabaseConnector (8.0.0)

dbAppendTable,DatabaseConnectorConnection,character-method

Insert rows into a table
dbConnect,DatabaseConnectorDriver-method

Create a connection to a DBMS
dbColumnInfo,DatabaseConnectorJdbcResult-method

Information about result types
dbClearResult,DatabaseConnectorJdbcResult-method

Clear a result set
dbClearResult,DatabaseConnectorDbiResult-method

Clear a result set
createZipFile

Compress files and/or folders into a single zip file
dbExecute,DatabaseConnectorDbiConnection,character-method

Change database state
dbColumnInfo,DatabaseConnectorDbiResult-method

Information about result types
dbDisconnect,DatabaseConnectorConnection-method

Disconnect (close) a connection
dbCreateTable,DatabaseConnectorConnection-method

Create a table in the database
dbGetInfo,DatabaseConnectorConnection-method

Get DBMS metadata
dbGetInfo,DatabaseConnectorDriver-method

Get DBMS metadata
dbFetch,DatabaseConnectorJdbcResult-method

Fetch records from a previously executed query
dbGetRowCount,DatabaseConnectorDbiResult-method

The number of rows fetched so far
dbGetQuery,DatabaseConnectorJdbcConnection,character-method

Retrieve results from a query
dbFetch,DatabaseConnectorDbiResult-method

Fetch records from a previously executed query
dbExistsTable,DatabaseConnectorConnection,character-method

Does a table exist?
dbExecute,DatabaseConnectorJdbcConnection,character-method

Change database state
dbGetQuery,DatabaseConnectorDbiConnection,character-method

Retrieve results from a query
dbGetRowCount,DatabaseConnectorJdbcResult-method

The number of rows fetched so far
dbGetRowsAffected,DatabaseConnectorJdbcResult-method

The number of rows affected
dbGetRowsAffected,DatabaseConnectorDbiResult-method

The number of rows affected
dbHasCompleted,DatabaseConnectorJdbcResult-method

Completion status
dbHasCompleted,DatabaseConnectorDbiResult-method

Completion status
dbIsValid,DatabaseConnectorDbiConnection-method

Is this DBMS object still valid?
dbIsValid,DatabaseConnectorJdbcConnection-method

Is this DBMS object still valid?
dbGetStatement,DatabaseConnectorDbiResult-method

Get the statement associated with a result set
dbGetStatement,DatabaseConnectorJdbcResult-method

Get the statement associated with a result set
dbRemoveTable,DatabaseConnectorConnection,ANY-method

Remove a table from the database
dbListFields,DatabaseConnectorConnection,character-method

List field names of a remote table
dbReadTable,DatabaseConnectorConnection,character-method

Read database tables as data frames
dbSendStatement,DatabaseConnectorConnection,character-method

Execute a data manipulation statement on a given database connection
dbListTables,DatabaseConnectorConnection-method

List remote tables
dbUnloadDriver,DatabaseConnectorDriver-method

Load and unload database drivers
dbSendQuery,DatabaseConnectorDbiConnection,character-method

Execute a query on a given database connection
dbSendQuery,DatabaseConnectorJdbcConnection,character-method

Execute a query on a given database connection
dbWriteTable,DatabaseConnectorConnection,ANY-method

Copy data frames to database tables
dbms

Get the database platform from a connection
inDatabaseSchema

Refer to a table in a database schema
getTableNames

List all tables in a database schema.
extractQueryTimes

Extract query times from a ParallelLogger log file
insertTable

Insert a table on the server
dbplyr_edition.DatabaseConnectorConnection

Declare dbplyr backend edition
querySql

Retrieve data to a data.frame
requiresTempEmulation

Does the DBMS require temp table emulation?
jdbcDrivers

How to download and use JDBC drivers for the various data platforms.
getAvailableJavaHeapSpace

Get available Java heap space
disconnect

Disconnect from the server
isSqlReservedWord

Test a character vector of SQL names for SQL reserved words
downloadJdbcDrivers

Download DatabaseConnector JDBC Jar files
dropEmulatedTempTables

Drop all emulated temp tables.
renderTranslateExecuteSql

Render, translate, execute SQL code
querySqlToAndromeda

Retrieves data to a local Andromeda object
reexports

Objects exported from other packages
renderTranslateQuerySqlToAndromeda

Render, translate, and query to local Andromeda
renderTranslateQuerySql

Render, translate, and query to data.frame
renderTranslateQueryApplyBatched

Render, translate, and perform process to batches of data.
existsTable

Does the table exist?
executeSql

Execute SQL code
assertTempEmulationSchemaSet

Assert the temp emulation schema is set
createConnectionDetails

createConnectionDetails
createDbiConnectionDetails

Create DBI connection details
DatabaseConnectorDriver-class

DatabaseConnectorDriver class.
DatabaseConnectorDriver

Create a DatabaseConnectorDriver object
computeDataHash

Compute hash of data
connect

connect
DatabaseConnectorJdbcResult-class

DatabaseConnector JDBC results class.
DatabaseConnectorDbiResult-class

DatabaseConnector DBI results class.
DatabaseConnector-package

DatabaseConnector: Connecting to Various Database Platforms