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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sounds like the Oracle JDBC entropy issue. Take a look at this article