Created
November 22, 2012 15:36
-
-
Save mjbommar/4131752 to your computer and use it in GitHub Desktop.
Example of connecting to an Oracle database using R and RJDBC
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
Can you ping to host (ndc-scan-r2)?
Sounds like the Oracle JDBC entropy issue. Take a look at this article
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
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!