JDBC连接Apache Drill

本文简单介绍drill的jdbc连接方式
1、下载drill,并解压
tar zxvf apache-drill-1.6.0.tar.gz -C /mofeng/tmp

2、修改配置文件
cd /mofeng/tmp/apache-drill-1.6.0/conf
cp drill-override-example.conf drill-override.conf
cat drill-override.conf

drill.exec: {
  cluster-id: "drillbits1"
  zk: {
        connect: "192.168.105.137:2181",
        #zk地址端口
        root: "drill2",
        #设置znode
        refresh: 500,
        timeout: 5000,
        retry: {
          count: 7200,
          delay: 500
        }
  },
}

3、192.168.105.137节点启动zookeeper

4、启动drill
/mofeng/tmp/apache-drill-1.6.0/bin/drillbit.sh start

5、编写Client代码如下:

package test;

/**
 * date: 2016年3月29日 下午3:55:53 
* @author mofeng */
import java.sql.*; public class DrillJDBCExample { static final String JDBC_DRIVER = "org.apache.drill.jdbc.Driver"; static final String DB_URL = "jdbc:drill:zk=192.168.105.137:2181/drill2/drillbits1"; //指定zk地址:端口/ZNODE/cluster-id static final String USER = "admin"; static final String PASS = "admin"; public static void main(String[] args) { Connection conn = null; Statement stmt = null; try{ Class.forName(JDBC_DRIVER); conn = DriverManager.getConnection(DB_URL,USER,PASS); stmt = conn.createStatement(); /* Perform a select on data in the classpath storage plugin. */ //String sql = "select employee_id,first_name,last_name from cp.`employee.json`"; String sql = "select * from cp.`employee.json`"; ResultSet rs = stmt.executeQuery(sql); while(rs.next()) { int id = rs.getInt("employee_id"); String first = rs.getString("first_name"); String last = rs.getString("last_name"); System.out.print("ID: " + id); System.out.print(", First: " + first); System.out.println(", Last: " + last); } rs.close(); stmt.close(); conn.close(); } catch(SQLException se) { //Handle errors for JDBC se.printStackTrace(); } catch(Exception e) { //Handle errors for Class.forName e.printStackTrace(); } finally { try{ if(stmt!=null) stmt.close(); } catch(SQLException se2) { } try { if(conn!=null) conn.close(); } catch(SQLException se) { se.printStackTrace(); } } } }

6、依赖包
drill-jdbc-all-1.6.0.jar

你可能感兴趣的:(drill)