使用 RODBC 连接 R 和 Vertica [英] Connect R and Vertica using RODBC
问题描述
这是我第一次连接到 Vertica.我已经使用 RODBC 库成功连接到 MySQL 数据库.
This is my first time connecting to Vertica. I have already connected to a MySQL database sucessfully by using RODBC library.
我在 vertica 中设置了数据库,并从 https 安装了 Windows 64 位 ODBC 驱动程序://my.vertica.com/download-community-edition/
I have the database setup in vertica and I installed the windows 64-bit ODBC driver from https://my.vertica.com/download-community-edition/
当我尝试使用 R 连接到 vertica 时,出现以下错误:
When I tried to connect to vertica using R, I get the below error:
channel = odbcDriverConnect(connection = "Server=myserver.edu;Database=mydb;User=mydb;Password=password")
Warning messages:
1: In odbcDriverConnect(connection = "Server=myserver.edu;Database=mydb;User=mydb;Password=password") :
[RODBC] ERROR: state IM002, code 0, message [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
2: In odbcDriverConnect(connection = "Server=myserver.edu;Database=mydb;User=mydb;Password=password") :
ODBC connection failed
谁能告诉我如何解决这个问题?或者还有其他方法可以使用 R 连接到 vertica 吗?
Can someone tell me how to fix this? Or is there any other ways to connect to vertica using R?
推荐答案
它可能不是最快的,但我更喜欢使用 R 中的 Vertica JDBC 驱动程序.让 ODBC 驱动程序在不同的操作系统上工作有点麻烦.如果您已经为其他应用程序安装了 Java 运行时环境 (JRE),那么这非常简单.
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.
从 MyVertica 门户下载适用于您的 Vertica 服务器版本的 Vertica JDBC 驱动程序.将驱动程序(.jar 文件)放置在适合您操作系统的合理位置.
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.
将 RJDBC 安装到您的工作区:
Install RJDBC into your workspace:
install.packages("RJDBC",dep=TRUE)
在您的 R 脚本中,加载 RJDBC 模块并创建 Vertica 驱动程序的实例,调整 classPath 参数以指向您下载的驱动程序的位置和文件名:
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")
然后运行您的 SQL 查询:
Then run your SQL queries:
myframe = dbGetQuery(vertica, "select Address,City,State,ZipCode from MyTable")
这篇关于使用 RODBC 连接 R 和 Vertica的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!