R RJDBC java.lang.OutOfMemoryError

user3567601 picture user3567601 · Jul 11, 2014 · Viewed 13.3k times · Source

I got following error while run dbGetQuery of RJDBC 0.2-4:

Error in .jcall(rp, "I", "fetch", stride) :    
  java.lang.OutOfMemoryError: Java heap space

Following is my code:

Sys.setenv(JAVA_HOME='C:/Program Files (x86)/Java/jdk1.7.0_25')
options(java.parameters='-Xmx1g')
library(rJava)
library(rjson)
library(RJDBC)

# Output Java version
.jinit()
print(.jcall("java/lang/System", "S", "getProperty", "java.version"))

jdbcDriver <<- JDBC(driverClass="oracle.jdbc.OracleDriver", classPath="C:/lib/dashboard_lib/ojdbc6.jar")
jdbcConnection <<- dbConnect(jdbcDriver, "...", "...", "...")
dataset <<- dbGetQuery(jdbcConnection, "select * from OPR_DATA.MV_REG_CTRY_MS_QUARTER_AMT")

Can anyone help me with this, thanks very much in advance

Answer

fc9.30 picture fc9.30 · Jun 28, 2016

Simply change the java.parameters to 8GB before load RJDBC package:

options(java.parameters = "-Xmx8048m")
library("RJDBC")