Connecting R to SQream with JDBC

This article describes how to create a new connection in R to SQream via the JDBC driver.

  

Make sure RJDBC is installed

In the R console, type:

> library(RJDBC)

If this succeeds, skip to the next step. Otherwise, install by typing:

> install.packages("RJDBC")

and then type

> library(RJDBC)

again to verify that the install succeeded.

Place the SQream JDBC JAR in a specified folder

You will need the following JAR file:

  • SqreamJDBC.jar

Our example assumes that the driver is copied to C:\Java\JARs (Windows). For Linux this would be an appropriate working directory.

Create a connection and test it 

Below is a sample connection script. Make sure to match it your connection and java classpaths. Specifically, note <your server address>, <your server port>, <your database name><SQream user name> and <password of SQream user>

We will first create a classpath and initialize the Java runtime around it, and then create a new connection.

In our example we're querying a table 'test_table' that has two columns, x and y and two rows of data.

> cp = c("C:\\Java\\JARs\\SqreamJDBC.jar")

> .jinit(classpath=cp)
[1] 0

> drv <- JDBC("com.sqream.jdbc.SQDriver","C:\\Java\\JARs\\SqreamJDBC.jar")

> con <- dbConnect(drv,"jdbc:Sqream://<your server address>:<your server port>/<your database name>;user=<SQream user name>;password=<password of SQream user>;cluster=<TRUE/FALSE>;ssl=<TRUE/FALSE>")
> dbGetQuery(con,"SELECT COUNT(*) as cnt FROM test_table")
    cnt
1   2
> dbGetQuery(con,"SELECT * FROM test_table")
   x y
1 1 5
2 4 6

For any further assistance please contact SQream support.

  • 90
  • 02-Sep-2018
  • 556 Views