Search code examples
renvironment-variablesdatabase-connectionrdatarenv

How to set the path for database drivers in R studio


I am trying to establish a connection to my database using an R package called DatabaseConnector

I am trying the below code

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

When I execute the above command, I get the below error

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.

But till few days, it was working fine and there was no issue with any driver location. I didn't make any changes to the driver's location etc. Not sure why this issue is being raised now. Can I seek your help, please?

Therefore, I tried the below two options.

a) I downloaded the driver and keyed in the downloaded location in the pathToDriver argument of the ConnectionDetails function as shown below. However, this doesn't solve the issue

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

b) I set an environment variable as suggested in the doc here. So, I have an environment variable as suggested which is DATABASECONNECTOR_JAR_FOLDER. This points to the jar file that I downloaded (Postgresql-42.2.19.jar)

c) Later, I tried using the downloadJdbcDrivers() function with pathToDriver updated to my jar file location but it still doesn't resolve the issue

Can I seek your help please?


Solution

  • Faced the same issue today, you only need to provide the folder location it seems, remove the postgresql-42.2.19.jar from pathToDriver and you should be good to go.