Domanda

I want to use R inside my Java application. I now there is some interface that can run R from Java (I think I will use JRI). The RJDBC library allow that R connect to a database using the JDBC driver.

What I want to do is pass the opened connection from the Java application to R ready for use.

This is possible?

EDIT: I can pass parameters for R and open a new connection from R. I can access Java objects from R with rJava.

The point if is possible pass the java.sql.Connection object that is in the Java to R and transform the connection in the R connection object that R uses to access the database with RJDBC.

È stato utile?

Soluzione

So I haven't done this... but I suspect if you really wanted to, there is a way. If you're using rJava to invoke R from Java (JRI style), then the java objects are really hosted on the JVM, not withing the R engine. Thus the connection object, along with all of it's resources wouldn't actually be moving from Java to R, really all of the calls from R would be forwarded out to java through rJava, and then the response would be sent back. So yeah, it should be possible. It does sound like more work than it's worth though.

Altri suggerimenti

This is not the answer you are looking for:

If you have the need to pass the connection arround, I assume that you have some kind of architectural design flaw. Rather keep the Connection in one place and pass on data transfer objects/pojos.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top