Skip to content

Instantly share code, notes, and snippets.

@schalekamp
Created November 3, 2021 18:23
Show Gist options
  • Save schalekamp/faa7d3b73be2e2285c61bd6d90a07e98 to your computer and use it in GitHub Desktop.
Save schalekamp/faa7d3b73be2e2285c61bd6d90a07e98 to your computer and use it in GitHub Desktop.
use RJDBC to connect to Clickhouse

First you have to make sure you have the java JDK installed.
In a terminal (ubuntu) do this.

sudo apt-get install default-jdk

Then in RStudio you have to install rJava and RJDBC

install.packages("rJava")
install.packages("RJDBC")

Finally download the JDBC driver and unzip it to a directory on your system. download link The zip-file has multiple .jar files which I parked in my local ~/ch directory.Now your system should be ready to connect!
(please change Sys.glob("~/ch/*.jar") to the location where you put your .jar files)

library(RJDBC)

drv <- JDBC("ru.yandex.clickhouse.ClickHouseDriver",
            Sys.glob("~/ch/*.jar"), "`")
conn <- dbConnect(drv, "jdbc:clickhouse://host:8123/dbname")

res <- dbGetQuery(conn, "select * from some_table limit 10;")
res
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment