Created
January 25, 2017 12:52
-
-
Save nickwhite917/2e0d55813d33b29abc73ef5902dbfd30 to your computer and use it in GitHub Desktop.
Connect to DB2 from R
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
| 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