Enable additional JVM parameters on JDBC() instantiation#42
Enable additional JVM parameters on JDBC() instantiation#42hjort wants to merge 2 commits intos-u:masterfrom
Conversation
|
Will this be merged? |
|
Well, I don't know. It's been a while. |
|
Well, it's not that simple. Unlike that classpath, there is no guarantee that you can set the JVM parameters - if JVM is already initialized (either by another package or because you're embedded in running Java) it's a no-op so the patch certainly isn't complete. Part of the issue that we're now going quite low-level - if this is about Java properties then you can set them in the runtime as well. So I think this is simply the wrong approach. If I read the original issue correctly, it may make more sense to allow setting Java properties (which can be done at runtime) instead of JVM startup-flags. |
30654b9 to
7675ca0
Compare
|
I came across this as I was trying to set a truststore on my RJDBC connection. Here's how I ended up doing it: # install.packages("RJDBC")
props <- c("-Djavax.net.ssl.trustStore=C:\\windows\\path\\to\\truststore.jks",
"-Djavax.net.ssl.trustStorePassword=changeit",
"-Djavax.net.ssl.trustStoreType=jks",
"-Doracle.net.ssl_version=1.2")
options(java.parameters = props)
library(RJDBC)
drv <- JDBC("oracle.jdbc.driver.OracleDriver","C:\\windows\\path\\to\\oracle\\driver\\ojdbc8-12.2.0.1.jar")
url <- "jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=tcps)(HOST=servername) PORT=2494))(CONNECT_DATA=(SERVICE_NAME=servicename)))"
conn <- dbConnect(drv, url, "user", "password")
chk <- dbGetQuery(conn, "SELECT 5432 betterport FROM DUAL ")
chk |
|
@tsykes yes, that only works if no other package has started Java before. What I was saying is that it may be better to set properties instead as they can be set even in a running JVM. So what I had in mind was something like: setProps <- function(...) {
l=list(...)
for (k in names(l))
J("java.lang.System")$setProperty(k, l[[k]])
}
setProps(
oracle.net.ssl_version="1.2",
javax.net.ssl.trustStoreType="jks",
javax.net.ssl.trustStorePassword="changeit",
javax.net.ssl.trustStore="C:\\windows\\path\\to\\truststore.jks")Does that work for you? That's what I was suggesting so if it works for you that's easy to add... Perhaps to clarify: if this is about run-time Java properties that's easy to implement, but that's not what this PR was addressing. This PR was about setting JVM start-up arguments which are a different beast since you can't change them once the JVM is running (e.g. the stack, heap etc.), so the approach in this PR doesn't work. If setting run-time properties is sufficient for the examples people use then that's a different, but much easier issue. |
When additional JVM parameters must be passed during the database connection, JDBC() class might accept an additional argument.
For instance, in order to connect to a Teiid data source constrained by SSL security requirements, one must specify the private JKS key through
-Djavax.net.ssl.trustStoreargument.With the current pull request, RJDBC is able to accept JVM additional arguments seamlessly, as it was already available in rJava package.
Here is an example of that functionality: