SQL Server Database Access in R via RJDBC

Requirements

Installation

install.packages("DBI")
install.packages("rJava")
install.packages("RJDBC")

Usage

library(DBI)
library(rJava)
library(RJDBC)

Driver for jTDS:

driver <- JDBC("net.sourceforge.jtds.jdbc.Driver", "$PATH-CONTAINING-JTDS/jtds.jar")

Driver for Microsoft JDBC Driver for SQL Server:

driver <- JDBC("com.microsoft.sqlserver.jdbc.SQLServerDriver", "$PATH-CONTAINING-SQLJDBC/sqljdbc.jar")

Once the driver is set, you can create your connection string and then your connection:

connection.string <- "" #Check the documentation for the driver to get details formatting your connection string.
connection <- dbConnect(driver, connection.string)

Now that we have our connection, we can use the standard DBI functions.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.