Jason Donnald
2014-Jul-21 03:08 UTC
[Rd] Displaying database records returned from postgresql to R through Java
Hi All,
I have a R script which returns a set of records from the postgresql to the
Java program and I want to print those records in Java.My script is like
this:
library(RPostgreSQL)
fnct1 <- function()
{
drv <- dbDriver("PostgreSQL")
r <- dbConnect(drv, host='local',
port='1234',dbname='db',
user='user', password='pwd')
rs <- dbSendQuery(r,"select * from table1 where colm1 =
'val1'")
temp <- fetch(rs,n=-1)
return(temp)
}
My Java code is :
c.parseAndEval("try(source(\"scpt.R\"),silent=TRUE)");
res = c.parseAndEval("try(fnct1(), silent=TRUE)");
System.out.println("table names are:"+ res);
When I am printing res above it is displaying
`table names are:org.rosuda.REngine.REXPGenericVector@681a9515+[1]named`
as output. When I do something like `.asString()` or inside the
`System.out.println()` above then it throws error. How can I print or
access each record returned by R to Java?
*NOTE:* When I am running the same script file from R itself then R is
displaying some 10 records but when I am trying through Java then nothing
is getting displayed
Regards,
Jason
[[alternative HTML version deleted]]
