I often run sql queries through R, and I've been working on getting a particular query to work. I provided quite a bit of info about it here in this question.
Long story short, I have a data frame I'd already pulled in, and I'm trying to loop through a sql query for each line of the dataframe I have. I'm running into some errors and it seems like (per the comments) that it may be rjdbc related. So I started a new question to deal specifically with the rjdbc errors. Here's my code:
library(RJDBC) ##
#create file path specific to the user
classpath_name="A:/ojdbc8.jar"
# Create connection driver and open connection
jdbcDriver <- JDBC(driverClass="oracle.jdbc.driver.OracleDriver", classPath=classpath_name) ## jar8 file supplied by company for connecting to the database. (2 other jar file options)
jdbcConnection <- dbConnect(jdbcDriver, "jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=tcps)(HOST=lhs-dbprod.forteresearchapps.com)(PORT=2879))(CONNECT_DATA=(SERVICE_NAME=pdblhs)))", "database", "adfhkjsdabfiewubbksdjblablablabla") ## DB hostname etc
Contacts<- dbGetQuery(jdbcConnection,
"select contact_id, username from lhs_oncore_prod.rv_contact where not username='barcode_user'")
(qmarks <- paste(rep("?", nrow(Contacts)), collapse = ","))
Access <- dbGetQuery(jdbcConnection,
paste("SELECT priv_check.contact_id, priv_check.protocol_id
FROM LHS_ONCORE_PROD.sv_user_pcl_permission priv_check
WHERE priv_check.function_name = 'CRPT-Subject Visits'
AND priv_check.contact_id in (", qmarks, ")"),
params = as.list(Contacts$CONTACT_ID) )
And here's the errors I run into:
Based on some comments in the other thread I tried this:
Access <- do.call(dbGetQuery, c(list(jdbcConnection, "SELECT priv_check.contact_id, priv_check.protocol_id FROM LHS_ONCORE_PROD.sv_user_pcl_permission priv_check WHERE priv_check.function_name = 'CRPT-Subject Visits' AND priv_check.contact_id in (", qmarks, ")"), params = as.list(Contacts$CONTACT_ID) ))
but that returned this:
Any ideas?