Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error connecting to amazon redshift from R - windows 10

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

like image 217
Viola Avatar asked Jan 07 '23 08:01

Viola


2 Answers

Exact same issue affected me. For some reason, download.file() grabbed a corrupted .jar. Dev in our group found the following fix:

  1. omit:

    download.file('http://s3.amazonaws.com/redshift-downloads/drivers/RedshiftJDBC41-1.1.13.1013.jar','RedshiftJDBC41-1.1.13.1013.jar')

  2. Instead download the .jar directly from http://docs.aws.amazon.com/redshift/latest/mgmt/configure-jdbc-connection.html

  3. Copy the .jar to your working directory.

  4. Run remainder of code.

like image 115
lowndrul Avatar answered Jan 19 '23 00:01

lowndrul


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")
like image 25
user3600910 Avatar answered Jan 19 '23 01:01

user3600910