Skip to content

Instantly share code, notes, and snippets.

@nickwhite917
Created January 25, 2017 12:52
Show Gist options
  • Select an option

  • Save nickwhite917/2e0d55813d33b29abc73ef5902dbfd30 to your computer and use it in GitHub Desktop.

Select an option

Save nickwhite917/2e0d55813d33b29abc73ef5902dbfd30 to your computer and use it in GitHub Desktop.
Connect to DB2 from R
library(RJDBC)
.jaddClassPath( "/home/517066/sqllib/SQLLIB/java/db2jcc_license_cu.jar" )
.jaddClassPath( "/home/517066/sqllib/SQLLIB/java/db2jcc4.jar" )
#Then we need to load the DB2 JDBC driver:
driver <- JDBC("com.ibm.db2.jcc.DB2Driver","home/517066/sqllib/SQLLIB/java/db2jcc4.jar")
#At this point we can establish a database connection:
conn = dbConnect(driver,
"jdbc:db2://ip:port/databaseName",
user="username",
password="password")
#Let’s run a query and #store the results into a data frame:
query = "SELECT * FROM SYSIBM.SYSTABLES WHERE NAME LIKE '%USER%'"
rs = dbSendQuery(conn, query)
data_frame = fetch(rs, -1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment