Apache Drill - connection to Drill in Embedded Mode [java]

丶灬走出姿态 提交于 2019-11-29 10:52:01

If you are connecting to a local embedded instance(without Zookeeper), you should use drillbit host directly like:

jdbc:drill:drillbit=<drillbit-host>:[port]

eg: jdbc:drill:drillbit=localhost

TLDR: jdbc:drill:drillbit=localhost:31010

First try using SQuirreL SQL client.

I am doing this with a vm running linux and apache, if this is all on one host you can replace with localhost.

first start drill-embedded on your vm or host eg:

/opt/apache-drill-1.1.0/bin/drill-embedded

this will start the embedded shell. check the port is open - it looks to be a different default than zookeeper etc:

sroot@localhost:/opt/apache-drill-1.1.0/bin [1089] netstat -anp | grep 31010

tcp 0 0 ::ffff:0.0.0.0:31010 :::* LISTEN 12934/java

you should be able to telnet localhost 31010 to this port.

you have to setup the jar driver as described here : https://drill.apache.org/docs/using-jdbc-with-squirrel-on-windows/

make sure the jar with the driver is executable.

but modify the string with the below - its different without zookeeper, eg in squirrel should look like this (thanks to others answers above too

jdbc:drill:drillbit=localhost:31010

you can replace localhost with the ip above - then test the connection.

the jar i'm using is the drill-jdbc-all-1.1.0.jar and the classname is org.apache.drill.jdbc.Driver

example squirrel driver configuration

I dont think you r using the correct jar. It seems you are using jdbc-all-jar. There are two jars. You need to add the other jar to make it work. Have added the maven pom. this should get you going

<dependency>
      <groupId>org.apache.drill.exec</groupId>
      <artifactId>drill-jdbc</artifactId>
      <version>1.1.0</version>
    </dependency>

you need to add the following dependency in your java project (I assume maven based)

<dependency>
    <groupId>org.apache.drill.exec</groupId>
    <artifactId>drill-jdbc</artifactId>
    <version>1.4.0</version>
</dependency>

Sample code (Assuming you want to run drill in embedded mode):

Class.forName("org.apache.drill.jdbc.Driver");
Connection connection =DriverManager.getConnection("jdbc:drill:zk=localhost");
Statement st = connection.createStatement();
ResultSet rs = st.executeQuery("SELECT * from cp.`employee`");
while(rs.next()){
System.out.println(rs.getString(1));
}

If you already started drill (assumning drill is running on local machine). Then you should change Connection:

Connection connection =DriverManager.getConnection("jdbc:drill:drillbit=localhost");

Check sample project: https://github.com/devender-yadav/DrillJDBC

NOTE: I have tested this for Drill 1.2, 1.3 and 1.4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!