Search code examples
javarrjavajri

Assign JDBC connection from Java to R


I would like to create JDBC connection in java and pass it to R. R would use it to write data to database. Can it be done? Is JRI running inside JVM?


Solution

  • If you want to do something like this:

    Java (create JDB connection) -> call R -> load Java via rJava -> call Java
    

    it will not work. You have two, different JVMs.

    If you want to do something like this:

    R -> call Java via rJava (create JDB connection) -> call Java yet again
    

    it should work as you are inside one JVM.

    You can think about introducing some helper class (e.g. Singleton that keeps your connection object). This way, you won't be forced to pass it around.