I want to connect to Drill by Java app, and so far I was trying to use JDBC to do it and I'm using example from https://github.com/vicenteg/DrillJDBCExample, but...
when I change DB_URL static variable to "jdbc:drill:zk=local" and start app i get exception:
java.sql.SQLNonTransientConnectionException: Running Drill in embedded mode using Drill's jdbc-all JDBC driver Jar file alone is not supported.
and so far I didn't found any workaround. Any idea how to connect to Drill in embedded mode? I don't want to set up distributed mode so far.
There is truly not much about it on the web.
Any help would be appreciated!
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