The RJDBC package enables an R application to use the Teradata JDBC Driver to access the Teradata Database.
DBI is the standard database interface for R, and RJDBC is an implementation of DBI that serves as an adapter to translate DBI actions into the corresponding JDBC actions. This combination enables R to use a JDBC Driver, such as the Teradata JDBC Driver.
R application ⇒ RJDBC ⇒ Teradata JDBC Driver ⇒ Teradata Database
Configuring R to use the Teradata JDBC Driver
NOTE: Installing RJDBC will also install the dependencies “DBI” and “rJava”.
Connect to the Teradata Database using RJDBC
NOTE: Loading RJDBC will also load the required packages “DBI” and “rJava”.
The Teradata JDBC driver is ready to connect to the Teradata database.
Using the R Console, enter the following steps below to make a Teradata connection, submit a SQL query, and disconnect:
drv = JDBC("com.teradata.jdbc.TeraDriver","c:\terajdbc\t
NOTE: A path on a UNIX machine would use forward slashes to separate its components and a semicolon between files.
conn = dbConnect(drv,"jdbc:teradata://system/TMODE=ANSI",
NOTE: Connection parameters are optional. The first ParameterName is separated from the DatabaseServerName by a forward slash character.
dbGetQuery(conn,"select * from dbc.dbcinfo")
Below is an example of an R script using the Teradata JDBC Driver to connect to a Teradata Database and submit queries.
dbSendUpdate(conn,"drop table employee")
dbSendUpdate(conn,"create table employee
empID INTEGER NOT NULL,
empName VARCHAR(30) NOT NULL,
empDept VARCHAR(50) NOT NULL,
dbSendQuery(conn,"INSERT INTO employee VALUES(100001,'Mike Smith','Product Development','QA engineer')")
dbSendQuery(conn,"INSERT INTO employee VALUES(100002,'James Parker','Marketing','Manager')")
dbGetQuery(conn, "select * from employee order by 1")
The output from the R Console shows: