如何在R studio中设置数据库驱动程序的路径

问题描述

我正在尝试使用名为 DatabaseConnector

的 R 包建立到我的数据库的连接

我正在尝试以下代码

connectionDetails <- DatabaseConnector::createConnectionDetails(dbms = "postgresql",user = "xxx",password = "xxx",server = "localhost/xxx",port = "9763")

当我执行上述命令时,出现以下错误

Error: The folder location pathToDriver = '  ' does not exist. Please set the folder to the location containing the JDBC driver. You can download most drivers using the `downloadJdbcDrivers()` function.

但直到几天前,它都运行良好,任何驱动程序位置都没有问题。我没有对驱动程序的位置等进行任何更改。不知道为什么现在提出这个问题。我可以寻求你的帮助吗?

因此,我尝试了以下两个选项。

a) 我下载了驱动程序并在 pathToDriver 函数ConnectionDetails 参数中键入下载位置,如下所示。但是,这并不能解决问题

pathToDriver = "C:\\Users\\test\\Downloads\\postgresql-42.2.19.jar")

b) 我按照文档 here 中的建议设置了一个环境变量。所以,我有一个建议的环境变量,它是 DATABASECONNECTOR_JAR_FOLDER。这指向我下载的 jar 文件 (Postgresql-42.2.19.jar)

c) 后来,我尝试使用 downloadJdbcDrivers() 函数pathToDriver 更新到我的 jar 文件位置,但它仍然没有解决问题

我可以寻求你的帮助吗?

解决方法

今天遇到同样的问题,您只需要提供看起来的文件夹位置,从 pathToDriver 中删除 postgresql-42.2.19.jar 就可以了。