OHDSI Home | Forums | Wiki | Github

DatabaseConnector::connect gives Error in rJava

Hi,
I try to connect to my PostgreSQL server using DatabaseConnector::connect, but I get the next error:

> conn <- DatabaseConnector::connect(connectionDetails)
Connecting using PostgreSQL driver
Error in rJava::.jcall(p, "Ljava/lang/Object;", "setProperty", names(properties)[I],  : 
  java.lang.NullPointerException

I couldn’t find a solution online. Can someone help me with that?
I tried removing and reinstalling java, rjava, DatabaseConnector, but nothing helped.

Hi @nadavrap

Here you must download the jars to connect to your database. Follow this link it will guide you on how to do that.

https://ohdsi.github.io/DatabaseConnectorJars/

If you need any further help let me know.

Kind regards,
Dinuja S’Wickrama

Obviously, I already downloaded dbms for postgresql. I tried doing so again, but the same error appears. Here are the steps that generate the error:

> DatabaseConnector::downloadJdbcDrivers('postgresql')
trying URL 'https://ohdsi.github.io/DatabaseConnectorJars/postgresqlV42.2.18.zip'
Content type 'application/zip' length 931791 bytes (909 KB)
==================================================
downloaded 909 KB

DatabaseConnector JDBC drivers downloaded to '/home/user1'.
> connectionDetails <- DatabaseConnector::createConnectionDetails(dbms = dbms,
+                                                                 server = server,
+                                                                 user = user)
> conn <- DatabaseConnector::connect(connectionDetails)
Connecting using PostgreSQL driver
Error in rJava::.jcall(p, "Ljava/lang/Object;", "setProperty", names(properties)[I],  : 
  java.lang.NullPointerException

Hi @nadavrap,

Can you tell me which java version are you using?
It is working fine with the below steps.

My Steps:

  1. Installed Java Version 8(JDK 8u211 and later)
  2. install.packages(“rJava”)
  3. Sys.setenv(JAVA_HOME=“C:/Program Files/Java/jdk1.8.0_301/”)
  4. install.packages(“DatabaseConnector”)
  5. Sys.setenv(“DATABASECONNECTOR_JAR_FOLDER” = “c:/temp/jdbcDrivers”)
  6. DatabaseConnector::downloadJdbcDrivers(‘postgresql’)
  7. connectionDetails ← DatabaseConnector::createConnectionDetails(dbms = “postgresql”,server = “server/database”,user = “postgres”,password=“admin”)
  8. conn ← DatabaseConnector::connect(connectionDetails)

Screenshot 2021-11-17 192416

Something is weird, I do have rJava, and I can load it. But when I tried to reinstall it, I get the next error:

Error: package or namespace load failed for ‘rJava’:
 .onLoad failed in loadNamespace() for 'rJava', details:
  call: dyn.load(file, DLLpath = DLLpath, ...)
  error: unable to load shared object '/home/user1/R/x86_64-koji-linux-gnu-library/4.0/00LOCK-rJava/00new/rJava/libs/rJava.so':
  libiconv.so.2: cannot open shared object file: No such file or directory

So I found libiconv.so.2, and add it to the ld path, but then I get another error when I try to reinstall rJava:

Error: package or namespace load failed for ‘rJava’:
 .onLoad failed in loadNamespace() for 'rJava', details:
  call: dyn.load(file, DLLpath = DLLpath, ...)
  error: unable to load shared object '/home/user1/R/x86_64-koji-linux-gnu-library/4.0/00LOCK-rJava/00new/rJava/libs/rJava.so':
  /home/user1/R/x86_64-koji-linux-gnu-library/4.0/00LOCK-rJava/00new/rJava/libs/rJava.so: undefined symbol: JNI_GetDefaultJavaVMInitArgs
Error: loading failed

So maybe it’s related to some other installations (working on Linux). Do you have any clue?

Hi @nadavrap,

I did the same thing on ubuntu using OracleJDK version 8, it is working fine. Can you kindly tell me which java versions are you using OpenJDK or Oracle JDK?

So, I tried it again after this incident, it is working fine with my steps.

Screenshot 2021-11-18 222638

Screenshot 2021-11-18 222912

Hopefully, the problem is with the OpenJDK. if you need further help to install Oracle JDK. Let me know.

Kind regards,
Dinuja

t