5

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.)

Wouter Thielen
  • 1,016
  • 9
  • 21
  • You may be better of posting this at communities.sas.com where you'll have SAS and some expert users who can answer this question. – Reeza Jul 03 '15 at 18:16
  • Thanks! I'll ask there as well. SAS seems solid to me, so at first I was thinking it would be a missing feature to catch such exceptions within the RJDBC package. I'll ask the RJDBC guys as well I guess. – Wouter Thielen Jul 04 '15 at 03:32

2 Answers2

2

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

Wouter Thielen
  • 1,016
  • 9
  • 21
FriedEgg
  • 201
  • 1
  • 3
0

I was having the same problems and tried the above solutions with no change. The solution on my computer was modifying the .Renviron file which holds the classpath to the java drivers. Replacing "JDBC_Drivers" with "WRDS_Drivers" was all that was needed:

CLASSPATH="C:/Users/nicol/Documents/WRDS_Drivers/sas.core.jar;C:/Users/nicol/Documents/WRDS_Drivers/sas.intrnet.javatools.jar"

Hysterio
  • 11
  • 3