Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R RJDBC java.lang.OutOfMemoryError

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

like image 988
user3567601 Avatar asked Jul 11 '14 06:07

user3567601


People also ask

How do I fix Java Lang OutOfMemoryError?

OutOfMemoryError: Java heap space. 1) An easy way to solve OutOfMemoryError in java is to increase the maximum heap size by using JVM options "-Xmx512M", this will immediately solve your OutOfMemoryError.

How do I fix Java heap space in Linux?

The solution to fix this problem is to increase the heap space(Default value maybe 128 MB). We can customize the heap space by specifying the JVM parameters -Xmx and -XX: MaxPermSize.

What causes Outofmemory exception Java?

OutOfMemoryError exception. Usually, this error is thrown when there is insufficient space to allocate an object in the Java heap. In this case, The garbage collector cannot make space available to accommodate a new object, and the heap cannot be expanded further.


3 Answers

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

options(java.parameters = "-Xmx8048m")
library("RJDBC")
like image 157
fc9.30 Avatar answered Oct 17 '22 13:10

fc9.30


It would fail for me using:

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

However,

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

worked.

like image 38
Sam Avatar answered Oct 17 '22 15:10

Sam


You can increase the memory as below and restart your Rstudio and it worked for me.

memory.limit(size=10000000000024)
like image 4
Nages Avatar answered Oct 17 '22 13:10

Nages