Connect R and Vertica using RODBC

痴心易碎 提交于 2019-11-28 11:24:30
bpanulla

It may not be the fastest, but I prefer to use the Vertica JDBC driver from R. Getting the ODBC drivers working is a little messy across different operating systems. If you already have a Java Runtime Environment (JRE) installed for other applications then this is fairly straightforward.

Download the Vertica JDBC drivers for your Vertica server version from the MyVertica portal. Place the driver (a .jar file) in a reasonable location for your operating system.

Install RJDBC into your workspace:

install.packages("RJDBC",dep=TRUE)

In your R script, load the RJDBC module and create an instance of the Vertica driver, adjusting the classPath argument to point to the location and filename of the driver you downloaded:

library(RJDBC)
vDriver <- JDBC(driverClass="com.vertica.jdbc.Driver", classPath="full\path\to\driver\vertica_jdbc_VERSION.jar")

Make a new connection using the driver object, substituting your connection details for the host, username and password:

vertica <- dbConnect(vDriver, "jdbc:vertica://host:5433/db", "username", "password")

Then run your SQL queries:

myframe = dbGetQuery(vertica, "select Address,City,State,ZipCode from MyTable")
dodomira

You have to use double slash in the classPath arguement in JDBC function. for example,

vDriver <- JDBC(driverClass="com.vertica.jdbc.Driver", 
classPath="C:\\Program   Files\\Vertica Systems\\JDBC\\vertica-jdk5-6.1.2-0.jar")

worked for me, while just copying and pasting the route failed.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!