Apache Drill access via Java JDBC API

Here is a quick draft on accessing Apache Drill via the java JDBC.

1. Add the Drill dependency-


2. Java Code to access Drill

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;
import java.util.Properties;

import org.apache.drill.exec.ExecConstants;
import org.apache.drill.exec.client.DrillClient;
import org.apache.drill.exec.proto.UserBitShared.QueryType;
import org.apache.drill.exec.rpc.RpcException;
import org.apache.drill.exec.rpc.user.QueryDataBatch;
import org.apache.drill.jdbc.Driver;

public class DrillJdbcTest {

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

	public static void method() throws SQLException {
		String sql = "SELECT * FROM cp.`employee.json` LIMIT 20";
		Connection con = null;
		String jdbcUrl = "jdbc:drill:zk=local";
		//String jdbcUrl = "jdbc:drill:zk=;schema=dfs.tmp";
		try {
			con = new Driver().connect(jdbcUrl, getDefaultProperties());
			Statement stmt = con.createStatement();
			ResultSet rs = stmt.executeQuery(sql);
			while (rs.next()) {
			System.out.println("DONE !!");
		} catch (Exception ex) {
		} finally {

	public static Properties getDefaultProperties() {
		final Properties properties = new Properties();
		properties.setProperty("drillJDBCUnitTests", "true");
		properties.setProperty(ExecConstants.HTTP_ENABLE, "false");
		return properties;


Yash Sharma is a Big Data & Machine Learning Engineer, A newbie OpenSource contributor, Plays guitar and enjoys teaching as part time hobby.
Talk to Yash about Distributed Systems and Data platform designs.

Leave a Reply

Your email address will not be published. Required fields are marked *