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

I want to connect to the Drill by Java app, and so far I have been trying to use JDBC for this, and I am using the example from https://github.com/vicenteg/DrillJDBCExample , but ... when I change the static DB_URL variable to "jdbc : drill: zk = local " and I launch the application I get exception:

java.sql.SQLNonTransientConnectionException: running Drill in native mode using Drill jdbc-all JDBC file for Jar file only is not supported.

and so far I have not found a workaround. Any idea how to connect to Drill in native mode? So far I do not want to configure distributed mode.

There really isn’t much on the Internet.

Any help would be appreciated!

+4
source share
4 answers

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

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

eg:  jdbc:drill:drillbit=localhost

+7
source

TL; DR: JDBC: drill: Drillbit = local: 31010

First try using the SQuirreL SQL client.

I do this with vm using linux and apache, if it's all on the same host, you can replace it with localhost.

start drilling on your vm or host first, for example:

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

this will launch the built-in shell. check that the port is open - it looks different by 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

telnet localhost 31010 .

jar, : https://drill.apache.org/docs/using-jdbc-with-squirrel-on-windows/

, .

: zookeeper, , (

JDBC: : Drillbit = : 31010

localhost ip - .

jar, , - drill-jdbc-all-1.1.0.jar, - org.apache.drill.jdbc.Driver

Squirrel

+5

, . , jdbc-all-jar. . , . maven pom.

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

you need to add the following dependency to your java project (I suppose 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 the 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 have already started the drill (assuming the drill is running on the local machine). Then you should change Connection:

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

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

NOTE. I checked this for Drill 1.2, 1.3 and 1.4

0
source

All Articles