When using the JDBC function to connect R to amazon redshift (I'm using windows 10) I get the following error:
Error in .jfindClass(as.character(driverClass)[1]) : class not found
The code I'm running is
install.packages("rJava")
install.packages("RJDBC")
library(rJava)
library(RJDBC)
download.file('http://s3.amazonaws.com/redshift-downloads/drivers/RedshiftJDBC41-1.1.13.1013.jar','RedshiftJDBC41-1.1.13.1013.jar')
driver <- JDBC("com.amazon.redshift.jdbc41.Driver", "RedshiftJDBC41-1.1.13.1013.jar", identifier.quote = "`")
To get more infos about the error I runned this:
.jclassLoader()$setDebug(1L)
and the full error trace is:
RJavaClassLoader: added 'RedshiftJDBC41-1.1.13.1013.jar' to the URL class path loader
RJavaClassLoader: adding Java archive file 'RedshiftJDBC41-1.1.13.1013.jar' to the internal class path
RJavaClassLoader: added 'C:/Users/user/Documents/R/win-library/3.2/RJDBC/java/RJDBC.jar' to the URL class path loader
RJavaClassLoader: adding Java archive file 'C:/Users/user/Documents/R/win-library/3.2/RJDBC/java/RJDBC.jar' to the internal class path
[email protected](com.amazon.redshift.jdbc41.Driver)
- URL loader did not find it: java.lang.ClassNotFoundException: com.amazon.redshift.jdbc41.Driver
RJavaClassLoader.findClass("com.amazon.redshift.jdbc41.Driver")
- trying class path "C:\Users\user\Documents\R\win-library\3.2\rJava\java"
Directory, can get 'C:\Users\user\Documents\R\win-library\3.2\rJava\java\com\amazon\redshift\jdbc41\Driver.class'? NO
- trying class path "C:\Users\user\Documents\R\win-library\3.2\RJDBC\java\RJDBC.jar"
JAR file, can get 'com/amazon/redshift/jdbc41/Driver'? NO
- trying class path "C:\Users\user\Desktop\Pricing"
Directory, can get 'C:\Users\user\Desktop\Pricing\com\amazon\redshift\jdbc41\Driver.class'? NO
- trying class path "C:\Users\user\Desktop\Pricing\RedshiftJDBC41-1.1.9.1009.jar"
JAR file, can get 'com/amazon/redshift/jdbc41/Driver'? NO
- trying class path "RedshiftJDBC41-1.1.9.1009.jar"
JAR file, can get 'com/amazon/redshift/jdbc41/Driver'? NO
- trying class path "." Directory, can get '.\com\amazon\redshift\jdbc41\Driver.class'? NO
- trying class path "C:\RedshiftJDBC41-1.1.9.1009.jar"
JAR file, can get 'com/amazon/redshift/jdbc41/Driver'? NO
- trying class path "RedshiftJDBC41-1.1.13.1013.jar"
JAR file, can get 'com/amazon/redshift/jdbc41/Driver'? NO
>> ClassNotFoundException
If you have any idea on something that could help it would be awesome! Thanks
Exact same issue affected me. For some reason, download.file()
grabbed a corrupted .jar. Dev in our group found the following fix:
omit:
download.file('http://s3.amazonaws.com/redshift-downloads/drivers/RedshiftJDBC41-1.1.13.1013.jar','RedshiftJDBC41-1.1.13.1013.jar')
Instead download the .jar directly from http://docs.aws.amazon.com/redshift/latest/mgmt/configure-jdbc-connection.html
Copy the .jar to your working directory.
Run remainder of code.
my recommendation for you is to connect redshift with RPostgreSQL package.
install.packages("RPostgreSQL")
library(RPostgreSQL)
drv <- dbDriver("PostgreSQL")
conn <-dbConnect(drv,host='host link',port='5439',dbname='dbname',user='xxx',password='yyy')
dbSendQuery(conn,"insert your query")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With