Skip to content

Instantly share code, notes, and snippets.

@mjbommar
Created November 22, 2012 15:36
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save mjbommar/4131752 to your computer and use it in GitHub Desktop.
Save mjbommar/4131752 to your computer and use it in GitHub Desktop.
Example of connecting to an Oracle database using R and RJDBC
# Set JAVA_HOME, set max. memory, and load rJava library
Sys.setenv(JAVA_HOME='/path/to/java_home')
options(java.parameters="-Xmx2g")
library(rJava)
# Output Java version
.jinit()
print(.jcall("java/lang/System", "S", "getProperty", "java.version"))
# Load RJDBC library
library(RJDBC)
# Create connection driver and open connection
jdbcDriver <- JDBC(driverClass="oracle.jdbc.OracleDriver", classPath="lib/ojdbc6.jar")
jdbcConnection <- dbConnect(jdbcDriver, "jdbc:oracle:thin:@//database.hostname.com:port/service_name_or_sid", "username", "password")
# Query on the Oracle instance name.
instanceName <- dbGetQuery(jdbcConnection, "SELECT instance_name FROM v$instance")
print(instanceName)
# Close connection
dbDisconnect(jdbcConnection)
@tmamiya
Copy link

tmamiya commented Apr 8, 2016

Hello,
I know you wrote this a long time ago, but I was wondering if i could pick your brain on a problem I am having.
In Rstudio in a windows environment
oDriver <- JDBC(driverClass="oracle.jdbc.OracleDriver", classPath="/home/user/ojdbc6.jar")
oracle <- dbConnect(oDriver, "jdbc:oracle:thin:@//ndc-scan-r2:1521/wmcatp1_be.walmart.com,"id","password")

This connects perfectly, however when I put this on my linux vm box and run it via Rscript i get an
Error in .jcall(drv@jdrv, "Ljava/sql/Connection;", "connect", as.character(url)[1], :
java.sql.SQLRecoverableException: IO Error: Unknown host specified

I have been at this for a couple hours trying different things but with no luck

Could you help a poor soul(me)? if not totally understand, just thought I'd ask.

Cheers!

@yht
Copy link

yht commented Oct 12, 2017

Can you ping to host (ndc-scan-r2)?

@alanmeeson
Copy link

Sounds like the Oracle JDBC entropy issue. Take a look at this article

Copy link

ghost commented Feb 26, 2019

Hi I'm having the exact same error as tmamiya
Does anyone have a suggestion to the solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment