从R-windows 10

时间:2016-04-05 15:24:49

标签: r windows-10 amazon-redshift rjdbc

当使用JDBC函数将R连接到amazon redshift时(我使用的是Windows 10),我收到以下错误:

Error in .jfindClass(as.character(driverClass)[1]) : class not found

我正在运行的代码是

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 = "`")

为了获得更多有关错误的信息,我运行了这个:

 .jclassLoader()$setDebug(1L)

并且完整的错误跟踪是:

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
RJavaClassLoader@33909752.findClass(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 

如果您对某些可能有用的东西有任何想法,那就太棒了!感谢

3 个答案:

答案 0 :(得分:6)

完全相同的问题影响了我。出于某种原因,download.file()抓住了一个损坏的.jar。我们小组的Dev发现了以下修复:

  1. 省略:

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

  2. 而是直接从http://docs.aws.amazon.com/redshift/latest/mgmt/configure-jdbc-connection.html

  3. 下载.jar
  4. 将.jar复制到您的工作目录。

  5. 运行剩余的代码。

答案 1 :(得分:1)

我的建议是将redshift与RPostgreSQL包连接起来。

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")

答案 2 :(得分:1)

嗨,我指的是你的代码

install.packages( “rJava”) install.packages( “RJDBC”) 库(rJava) 库(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 = "`")

您编写驱动程序对象的位置,语法为

driver <- JDBC("CLASSNAME","PATH WHERE REDSHIFT JAR FILE IS DOWNLOADED')

我有同样的错误,一旦我意识到我必须走正确的道路,我就可以连接。 我对JDBC的第二个论点是'C:\ Users \ person.name \ Downloads \ RedshiftJDBC41-1.1.13.1013.jar'

希望这有帮助