R Language with JDBC Driver

This article shows how to use Treasure Data with the R language by using the RJDBC package.

Table of Contents

Tutorial Video

Here’s a video to show you how to connect to Treasure Data from R.


You can download the Treasure Data JDBC driver from the link below:

This driver only works with Treasure Data. It does not work in other environments such as your local Hadoop / Hive cluster.

Installing the RJDBC Package

First, install the RJDBC Package as shown below:

$ R
> install.packages("RJDBC",dep=TRUE)

Your Locale Endpoint

Where you plan to run Treasure Data and this feature affects how you access the feature. Access the feature described in this article from the same domain that you access the Treasure Data console.

Region Endpoint Console
US Region api.treasuredata.com console.treasuredata.com
Tokyo Region api.treasuredata.co.jp console.treasuredata.co.jp

Issuing Queries

To issue queries, use the RJDBC package together with the Treasure Data JDBC driver.

drv <- JDBC("com.treasuredata.jdbc.TreasureDataDriver",
conn <- dbConnect(drv,
dbGetQuery(conn, "SELECT COUNT(1) AS cnt FROM www_access")

If your account is only Batch(Hive) plan, change type from presto to hive.

NOTE: RJDBC is required to use Username and Passowrd for authentication. Currently, APIKEY is not supported.

Last modified: Jan 18 2018 08:46:12 UTC

If this article is incorrect or outdated, or omits critical information, let us know. For all other issues, access our support channels.