OHDSI Home | Forums | Wiki | Github

Setup for DatabaseConnector Development

Hi all,

I am working on getting set up to do development on DatabaseConnector, but I’ve run into an error with rJava. I have a Postgres database running and locally and have successfully connected to it, but receive a ClassNotFoundException when I try to execute a query. After inspecting the traceback and the error object itself, it appears the class rJava cannot find is org.ohdsi.databaseConnector.BatchedQuery, the one packaged as a JAR with the repository. It should be noted that I am working off of the “develop” branch of the DatabaseConnector repository after reading about the impending release of DatabaseConnector 2.0. Here are the contents of my RStudio session:

connectionDetails <- createConnectionDetails(dbms = “postgresql”, user = “trinetx”, password=“trinetx”, server = “localhost/trinetx”, schema = “trinetx”)
conn <- connect(connectionDetails)
Connecting using PostgreSQL driver
querySql(conn, “SELECT COUNT(*) FROM person”)
Error: Error executing SQL:
java.lang.ClassNotFoundException
An error report has been created at /Users/alex.lafreniere/work/sf/DatabaseConnector/errorReport.txt

And here is the error report:

DBMS:
postgresql

Error:
java.lang.ClassNotFoundException

SQL:
SELECT COUNT(*) FROM person

R version:
R version 3.4.1 (2017-06-30)

Platform:
x86_64-apple-darwin15.6.0

Attached base packages:

  • stats
  • graphics
  • grDevices
  • utils
  • datasets
  • methods
  • base

Other attached packages:

  • DatabaseConnector (2.0.0)

Any help would be greatly appreciated!

I was able to connect and successfully query against Postgres using the code on the master branch of DatabaseConnector. It looks like the code on the develop branch just isn’t ready for prime time.

Actually, I was just about to merge the develop branch into master, so it SHOULD be ready for prime time. It is working fine on my Windows machine as well as our (Linux) CI environment.

I noticed there was some junk in the jar file and removed it. Could you try the develop branch again?

No change, still getting a ClassNotFoundException on the rJava call to BatchedQuery when on the develop branch. Here’s a screenshot of my RStudio traceback when I get the error:

Ok, I just changed the target Java version, which was the problem for another Mac user. Could you try if this new version works for you?

I’m sorry to say, still no change. I still get a ClassNotFoundException when trying to execute my query (connecting to the database works just fine). For what it’s worth, I’m on Java 8:

$ java -version
java version “1.8.0_121”
Java™ SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot™ 64-Bit Server VM (build 25.121-b13, mixed mode)

Hmmm, I now have tested it myself on Windows, Linux, and MacOS, so it can’t be the operating system. I’m at a loss why you are experiencing this problem. Could you

  1. Make sure you have a clean install of DatabaseConnector? Close all instances of R, open only one, uninstall DatabaseConnector and then install again

  2. Take a look at your classpath using rJava::.jclassPath()? (after you’ve called library(DatabaseConnector))

To be clear, I’m trying to get the develop branch working in a development environment so that I can extend DatabaseConnector, so rather than uninstall the package (I never had it installed in the first place) I deleted my clone of the DatabaseConnector repository then cloned and built it again. I still got the same error, but it looks like the class path is the culprit:

conn <- connect(connectionDetails)
Connecting using PostgreSQL driver
querySql(conn,“SELECT COUNT(*) FROM person”)
Error: Error executing SQL:
java.lang.ClassNotFoundException
An error report has been created at /Users/alex.lafreniere/work/sf/DatabaseConnector/errorReport.txt
Called from: .createErrorReport(attr(connection, “dbms”), err$message, sql)
Browse[1]> rJava::.jclassPath()
[1] “/Library/Frameworks/R.framework/Versions/3.4/Resources/library/rJava/java”
[2] “/Library/Frameworks/R.framework/Versions/3.4/Resources/library/SqlRender/java”
[3] “/Library/Frameworks/R.framework/Versions/3.4/Resources/library/SqlRender/java/SqlRender.jar”
[4] “/Users/alex.lafreniere/work/sf/DatabaseConnector/java”
[5] “/Users/alex.lafreniere/work/sf/DatabaseConnector/inst/java/postgresql-9.3-1101.jdbc4.jar”

I notice that none of these paths are “/Users/alex.lafreniere/work/sf/DatabaseConnector/inst/java/DatabaseConnector.jar” which is probably what I want (but you can correct me on that one). Am I doing the right thing to set up DatabaseConnector for development?

You’re right, the class path should look something like this:

> rJava::.jclassPath()
[1] "C:\\R\\R-3.4.0\\library\\rJava\\java"                                           
[2] "C:\\R\\R-3.4.0\\library\\DatabaseConnector\\java"                               
[3] "C:\\R\\R-3.4.0\\library\\DatabaseConnector\\java\\DatabaseConnector.jar"        
[4] "C:\\R\\R-3.4.0\\library\\DatabaseConnector\\java\\postgresql-9.3-1101.jdbc4.jar"
[5] "C:\\R\\R-3.4.0\\library\\SqlRender\\java"                                       
[6] "C:\\R\\R-3.4.0\\library\\SqlRender\\java\\SqlRender.jar"   

The class path should be set on loading of the package here. Either it doesn’t get there, or adding it to the class path fails. Could you try adding it manually?

rJava::.jaddClassPath("/Users/alex.lafreniere/work/sf/DatabaseConnector/inst/java/DatabaseConnector.jar")

Another thing to try to see if it is your development environment is installing the package in the ‘regular’ way:

devtools::install_github("ohdsi/DatabaseConnector", ref = "develop")

Manually adding the class path worked. After seeing that, I assumed the onLoad function wasn’t being called, so I threw in a writeLines() call just inside it and set a breakpoint on the call to jpackage. I can see the writeLines() call outputting to the console when I Cmd + Shift + L but the breakpoint is never hit. Breakpoints work in other files. Very strange.

t