Search code examples
javarsasrjdbc

Java exception error during RJDBC::dbConnect: how to silently ignore?


I am trying to connect to a SAS-driven remote database from within R, using RJDBC. The first time I do a dbConnect, I get an error:

Error in .jcall(drv@jdrv, "Ljava/sql/Connection;", "connect", as.character(url)[1],
: java.lang.NoClassDefFoundError: com/sas/net/crypto/CryptoException

When I do the dbConnect a second time after the first call, it connects fine, and I get back an object of class JDBCConnection.

I looked in the sas.core.jar file (from the latest 94M2 SAS JDBC drivers), and can see CryptoException listed in there. However, I am also curious why it was trying to throw a CryptoException.

Question 1: How can I silently ignore the error on the first dbConnect call?

Question 2: Why was it trying to throw a CryptoException? What can I do to prevent this? (This may cancel question 1.)


Solution

  • This is the same question as shared on the SAS Support Communities page:

    https://communities.sas.com/thread/80620

    There you shared the code you are using

    https://github.com/wthielen/wrds/blob/7edfbfe89ddc329618be72e591cc0bd50e294ea4/R/wrds.R#L47

    In this code, the problem appears to be that you are trying to set the classpath before initializing the JVM. Using .jinit() before the call to .jaddClassPath should correct the issue. In the doc for .jinit and since you are developing a package, you may want to use .jpackage instead of .jinit

    https://www.rforge.net/doc/packages/rJava/jpackage.html