Treasure Data JDBC Driver

This article will explain how to use Treasure Data’s JDBC (Java Database Connectivity) driver. This driver enables you to use Treasure Data with a standard JDBC interface.

Table of Contents


You can download the driver itself from the link below. The driver is still in beta; any feedback is appreciated.

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


Use the following JDBC URL format with your Java application or JDBC-compliant SQL/BI tool.


For example, to access a database named “sample_db” in your account, your JDBC URL would be:


You can choose the query engine (Hive or Presto) by the parameter.


If you are trying to connect from behind a proxy, you can specify the proxy settings using the following properties:

  • httpproxyhost
  • httpproxyport
  • httpproxyuser
  • httpproxypassword

For example:


Query Execution Internals

Because Treasure Data is a cloud service, its JDBC driver behaves in a slightly different manner compared to that of traditional RDBMs.

SELECT Statement

When a SELECT statement is sent to the driver, the driver will issue the query to the cloud. The driver will regularly poll the job results while the jobs run on the cloud. The query may take several hours, we recommend that you use a background thread.

INSERT Statement

When a INSERT statement is sent to the driver, the data is first buffered in local memory. The data is uploaded into the cloud every 5 minutes. Please note that the upload doesn’t occur in realtime.

Sample Java Program

Here’s a sample Java program that executes a SELECT statement. This program counts the number of records within the testdb.www_access table.

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Properties;
import com.treasure_data.jdbc.TreasureDataDriver;

public class JDBCSample {
  public static void loadSystemProperties() throws IOException {
    Properties props = System.getProperties();

  public static void main(String[] args) throws Exception {
    try {
    } catch (ClassNotFoundException e) {

    Connection conn = DriverManager.getConnection(
    Statement stmt = conn.createStatement();
    String sql = "SELECT count(1) FROM www_access";
    System.out.println("Running: " + sql);
    ResultSet res = stmt.executeQuery(sql);
    while ( {

This file is only required if using INSERT statements. If you are only using SELECT statement, this file is not required.

td.api.key=<your API key>

If this article is incorrect or outdated, or omits critical information, please let us know. For all other issues, please see our support channels. Live chat with our staff also works well.