# Connecting dremio with python using jdbc

**URL:** <https://community.dremio.com/t/connecting-dremio-with-python-using-jdbc/3239>\
**Category:** Uncategorized\
**Created:** [April 22, 2019, 1:05pm UTC](https://community.dremio.com/t/connecting-dremio-with-python-using-jdbc/3239 "2019-04-22T13:05:46Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![abhba](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@abhba](https://community.dremio.com/u/abhba)\
**Post date:** [April 22, 2019, 1:05pm UTC](https://community.dremio.com/t/connecting-dremio-with-python-using-jdbc/3239/1 "2019-04-22T13:05:46Z")

</div>

I am trying to connect dremio with python in zeppelin notebook and I have given the connection string below but getting parser error .

%jdbc(dremio)  
import jaydebeapi

conn = jaydebeapi.connect(“com.dremio.jdbc.Driver”,  
“jdbc:dremio:direct=xx.xx.xx.xx:31010”,  
[“username”, “password123”],  
‘/usr/hdp/current/zeppelin-server/lib/dremio-jdbc-driver-3.1.9-201904051346520183-a35b753.jar’,)  
curs = conn.cursor()  
curs.execute(“show databases”)  
curs.fetchall()

error:java.sql.SQLException: PARSE ERROR: Failure parsing the query.

SQL Query import jaydebeapi

conn = jaydebeapi.connect(“com.dremio.jdbc.Driver”,  
“jdbc:dremio:direct=xx.xx.xx.xx:31010”,  
[“username”, “password123”],  
‘/usr/hdp/current/zeppelin-server/lib/dremio-jdbc-driver-3.1.9-201904051346520183-a35b753.jar’,)  
curs = conn.cursor()  
curs.execute(“show databases”)  
curs.fetchall()  
startLine 1  
startColumn 1  
endLine 1  
endColumn 6  
SQL Query import jaydebeapi

---

<div class="post-metadata">

**Author:** ![ben](https://sea2.discourse-cdn.com/flex020/user_avatar/community.dremio.com/ben/32/1367_2.png) [@ben](https://community.dremio.com/u/ben)\
**Post date:** [April 23, 2019, 5:13pm UTC](https://community.dremio.com/t/connecting-dremio-with-python-using-jdbc/3239/2 "2019-04-23T17:13:32Z")

</div>

@abhba,

The PARSE ERROR implies that there’s something wrong with the SQL, but I can’t see anything that jumps out.

Have you tried any other query that you know works in the Dremio UI?

---

<div class="post-metadata">

**Author:** ![abhba](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@abhba](https://community.dremio.com/u/abhba)\
**Post date:** [April 23, 2019, 5:32pm UTC](https://community.dremio.com/t/connecting-dremio-with-python-using-jdbc/3239/3 "2019-04-23T17:32:54Z")

</div>

Hi Ben,  
Thanks for getting back to me.Yeah I tried but I don’t know why it didn’t work for me .Are you using Zeppelin notebook for dremio ??

Regards,

Abhay Singh

---

<div class="post-metadata">

**Author:** ![laurent](https://sea2.discourse-cdn.com/flex020/user_avatar/community.dremio.com/laurent/32/16_2.png) [@laurent](https://community.dremio.com/u/laurent)\
**Post date:** [April 23, 2019, 5:53pm UTC](https://community.dremio.com/t/connecting-dremio-with-python-using-jdbc/3239/4 "2019-04-23T17:53:39Z")

</div>

@abhba you should be able to see some failed queries in Dremio UI with possibly more details. Could you please check and share with us?

---

<div class="post-metadata">

**Author:** ![abhba](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@abhba](https://community.dremio.com/u/abhba)\
**Post date:** [April 24, 2019, 8:40am UTC](https://community.dremio.com/t/connecting-dremio-with-python-using-jdbc/3239/5 "2019-04-24T08:40:18Z")

</div>

Hi Laurent,  
same error is there in the UI job section .

---

<div class="post-metadata">

**Author:** ![ben](https://sea2.discourse-cdn.com/flex020/user_avatar/community.dremio.com/ben/32/1367_2.png) [@ben](https://community.dremio.com/u/ben)\
**Post date:** [April 24, 2019, 3:20pm UTC](https://community.dremio.com/t/connecting-dremio-with-python-using-jdbc/3239/6 "2019-04-24T15:20:54Z")

</div>

@abhba,  
That you see the job in Dremio at least means you’re connecting to Dremio 🙂

If you open up the profile for the job, you’ll see both the SQL that was submitted and (hopefully) a more detailed error message.

Can you share the profile?

> **[How To Share A Query Profile](https://www.dremio.com/tutorials/share-query-profile-dremio/)**
>
> Tutorial explaining how to share a query profile in Dremio.

---

<div class="post-metadata">

**Author:** ![abhba](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@abhba](https://community.dremio.com/u/abhba)\
**Post date:** [April 24, 2019, 5:42pm UTC](https://community.dremio.com/t/connecting-dremio-with-python-using-jdbc/3239/7 "2019-04-24T17:42:52Z")

</div>

Yeah sure ben .Tomorrow I will do that .

---

<div class="post-metadata">

**Author:** ![abhba](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@abhba](https://community.dremio.com/u/abhba)\
**Post date:** [April 25, 2019, 5:29am UTC](https://community.dremio.com/t/connecting-dremio-with-python-using-jdbc/3239/8 "2019-04-25T05:29:49Z")

</div>

Hi ben,  
this the complete error .

PARSE ERROR: Failure parsing the query.

SQL Query import jaydebeapi

conn = jaydebeapi.connect(“com.dremio.jdbc.Driver”,  
“jdbc:dremio:direct=xx.xx.xx.xxx:31010”,  
[“user”, “pass123”],  
‘/usr/hdp/current/zeppelin-server/lib/dremio-jdbc-driver-3.1.9-201904051346520183-a35b753.jar’,)  
curs = conn.cursor()  
curs.execute(‘SELECT \* FROM “Mongo\_Db”.mydb.“customer”’)  
curs.fetchall()  
startLine 1  
startColumn 1  
endLine 1  
endColumn 6  
SQL Query import jaydebeapi

conn = jaydebeapi.connect(“com.dremio.jdbc.Driver”,  
“jdbc:dremio:direct=xx.xx.xx.xxx:31010”,  
[“user”, “pss123”],  
‘/usr/hdp/current/zeppelin-server/lib/dremio-jdbc-driver-3.1.9-201904051346520183-a35b753.jar’,)  
curs = conn.cursor()  
curs.execute(‘SELECT \* FROM “Mongo\_Db”.mydb.“customer”’)  
curs.fetchall()

(org.apache.calcite.sql.parser.SqlParseException) Encountered “import” at line 1, column 1.  
Was expecting one of:  
“SHOW” …  
“DESCRIBE” …  
“USE” …  
“CREATE” …  
“DROP” …  
“ALTER” …  
“REFRESH” …  
“LOAD” …  
“COMPACT” …  
“SET” …  
“RESET” …  
“WITH” …  
“+” …  
“-” …  
“NOT” …  
“EXISTS” …  
\<UNSIGNED\_INTEGER\_LITERAL\> …  
\<DECIMAL\_NUMERIC\_LITERAL\> …  
\<APPROX\_NUMERIC\_LITERAL\> …  
\<BINARY\_STRING\_LITERAL\> …  
\<PREFIXED\_STRING\_LITERAL\> …  
\<QUOTED\_STRING\> …  
\<UNICODE\_STRING\_LITERAL\> …  
“TRUE” …  
“FALSE” …  
“UNKNOWN” …  
“NULL” …  
\<LBRACE\_D\> …  
\<LBRACE\_T\> …  
\<LBRACE\_TS\> …  
“DATE” …  
“TIME” …  
“TIMESTAMP” …  
“INTERVAL” …  
“CONTAINS(” …  
“?” …  
“CAST” …  
“EXTRACT” …  
“POSITION” …  
“CONVERT” …  
“TRANSLATE” …  
“OVERLAY” …  
“FLOOR” …  
“CEIL” …  
“CEILING” …  
“SUBSTRING” …  
“TRIM” …  
“CLASSIFIER” …  
“MATCH\_NUMBER” …  
“RUNNING” …  
“PREV” …  
“NEXT” …  
\<LBRACE\_FN\> …  
“MULTISET” …  
“ARRAY” …  
“PERIOD” …  
“SPECIFIC” …  
 …  
\<QUOTED\_IDENTIFIER\> …  
\<BACK\_QUOTED\_IDENTIFIER\> …  
\<BRACKET\_QUOTED\_IDENTIFIER\> …  
\<UNICODE\_QUOTED\_IDENTIFIER\> …  
“ABS” …  
“AVG” …  
“CARDINALITY” …  
“CHAR\_LENGTH” …  
“CHARACTER\_LENGTH” …  
“COALESCE” …  
“COLLECT” …  
“COVAR\_POP” …  
“COVAR\_SAMP” …  
“CUME\_DIST” …  
“COUNT” …  
“CURRENT\_DATE” …  
“CURRENT\_TIME” …  
“CURRENT\_TIMESTAMP” …  
“DENSE\_RANK” …  
“ELEMENT” …  
“EXP” …  
“FIRST\_VALUE” …  
“FUSION” …  
“GROUPING” …  
“HOUR” …  
“LAG” …  
“LEAD” …  
“LAST\_VALUE” …  
“LN” …  
“LOCALTIME” …  
“LOCALTIMESTAMP” …  
“LOWER” …  
“MAX” …  
“MIN” …  
“MINUTE” …  
“MOD” …  
“MONTH” …  
“NTILE” …  
“NULLIF” …  
“OCTET\_LENGTH” …  
“PERCENT\_RANK” …  
“POWER” …  
“RANK” …  
“REGR\_SXX” …  
“REGR\_SYY” …  
“ROW\_NUMBER” …  
“SECOND” …  
“SQRT” …  
“STDDEV\_POP” …  
“STDDEV\_SAMP” …  
“SUM” …  
“UPPER” …  
“TRUNCATE” …  
“USER” …  
“VAR\_POP” …  
“VAR\_SAMP” …  
“YEAR” …  
“CURRENT\_CATALOG” …  
“CURRENT\_DEFAULT\_TRANSFORM\_GROUP” …  
“CURRENT\_PATH” …  
“CURRENT\_ROLE” …  
“CURRENT\_SCHEMA” …  
“CURRENT\_USER” …  
“SESSION\_USER” …  
“SYSTEM\_USER” …  
“NEW” …  
“CASE” …  
“CURRENT” …  
“CURSOR” …  
“ROW” …  
“(” …  
“SELECT” …  
“VALUES” …  
“TABLE” …  
“EXPLAIN” …  
“INSERT” …  
“UPSERT” …  
“DELETE” …  
“UPDATE” …  
“MERGE” …  
“CALL” …

```
com.dremio.exec.planner.sql.parser.impl.ParserImpl.convertException():355
com.dremio.exec.planner.sql.parser.impl.ParserImpl.normalizeException():136
org.apache.calcite.sql.parser.SqlParser.parseQuery():138
org.apache.calcite.sql.parser.SqlParser.parseStmt():163
com.dremio.exec.planner.sql.SqlConverter.parse():180
com.dremio.exec.planner.sql.handlers.commands.CommandCreator.getSqlCommand():249
com.dremio.exec.planner.sql.handlers.commands.CommandCreator.toCommand():205
com.dremio.exec.work.foreman.AttemptManager.run():282
java.util.concurrent.ThreadPoolExecutor.runWorker():1149
java.util.concurrent.ThreadPoolExecutor$Worker.run():624
java.lang.Thread.run():748

```

Caused By (com.dremio.exec.planner.sql.parser.impl.ParseException) Encountered “import” at line 1, column 1.  
Was expecting one of:  
“SHOW” …  
“DESCRIBE” …  
“USE” …  
“CREATE” …  
“DROP” …  
“ALTER” …  
“REFRESH” …  
“LOAD” …  
“COMPACT” …  
“SET” …  
“RESET” …  
“WITH” …  
“+” …  
“-” …  
“NOT” …  
“EXISTS” …  
\<UNSIGNED\_INTEGER\_LITERAL\> …  
\<DECIMAL\_NUMERIC\_LITERAL\> …  
\<APPROX\_NUMERIC\_LITERAL\> …  
\<BINARY\_STRING\_LITERAL\> …  
\<PREFIXED\_STRING\_LITERAL\> …  
\<QUOTED\_STRING\> …  
\<UNICODE\_STRING\_LITERAL\> …  
“TRUE” …  
“FALSE” …  
“UNKNOWN” …  
“NULL” …  
\<LBRACE\_D\> …  
\<LBRACE\_T\> …  
\<LBRACE\_TS\> …  
“DATE” …  
“TIME” …  
“TIMESTAMP” …  
“INTERVAL” …  
“CONTAINS(” …  
“?” …  
“CAST” …  
“EXTRACT” …  
“POSITION” …  
“CONVERT” …  
“TRANSLATE” …  
“OVERLAY” …  
“FLOOR” …  
“CEIL” …  
“CEILING” …  
“SUBSTRING” …  
“TRIM” …  
“CLASSIFIER” …  
“MATCH\_NUMBER” …  
“RUNNING” …  
“PREV” …  
“NEXT” …  
\<LBRACE\_FN\> …  
“MULTISET” …  
“ARRAY” …  
“PERIOD” …  
“SPECIFIC” …  
 …  
\<QUOTED\_IDENTIFIER\> …  
\<BACK\_QUOTED\_IDENTIFIER\> …  
\<BRACKET\_QUOTED\_IDENTIFIER\> …  
\<UNICODE\_QUOTED\_IDENTIFIER\> …  
“ABS” …  
“AVG” …  
“CARDINALITY” …  
“CHAR\_LENGTH” …  
“CHARACTER\_LENGTH” …  
“COALESCE” …  
“COLLECT” …  
“COVAR\_POP” …  
“COVAR\_SAMP” …  
“CUME\_DIST” …  
“COUNT” …  
“CURRENT\_DATE” …  
“CURRENT\_TIME” …  
“CURRENT\_TIMESTAMP” …  
“DENSE\_RANK” …  
“ELEMENT” …  
“EXP” …  
“FIRST\_VALUE” …  
“FUSION” …  
“GROUPING” …  
“HOUR” …  
“LAG” …  
“LEAD” …  
“LAST\_VALUE” …  
“LN” …  
“LOCALTIME” …  
“LOCALTIMESTAMP” …  
“LOWER” …  
“MAX” …  
“MIN” …  
“MINUTE” …  
“MOD” …  
“MONTH” …  
“NTILE” …  
“NULLIF” …  
“OCTET\_LENGTH” …  
“PERCENT\_RANK” …  
“POWER” …  
“RANK” …  
“REGR\_SXX” …  
“REGR\_SYY” …  
“ROW\_NUMBER” …  
“SECOND” …  
“SQRT” …  
“STDDEV\_POP” …  
“STDDEV\_SAMP” …  
“SUM” …  
“UPPER” …  
“TRUNCATE” …  
“USER” …  
“VAR\_POP” …  
“VAR\_SAMP” …  
“YEAR” …  
“CURRENT\_CATALOG” …  
“CURRENT\_DEFAULT\_TRANSFORM\_GROUP” …  
“CURRENT\_PATH” …  
“CURRENT\_ROLE” …  
“CURRENT\_SCHEMA” …  
“CURRENT\_USER” …  
“SESSION\_USER” …  
“SYSTEM\_USER” …  
“NEW” …  
“CASE” …  
“CURRENT” …  
“CURSOR” …  
“ROW” …  
“(” …  
“SELECT” …  
“VALUES” …  
“TABLE” …  
“EXPLAIN” …  
“INSERT” …  
“UPSERT” …  
“DELETE” …  
“UPDATE” …  
“MERGE” …  
“CALL” …

```
com.dremio.exec.planner.sql.parser.impl.ParserImpl.generateParseException():26589
com.dremio.exec.planner.sql.parser.impl.ParserImpl.jj_consume_token():26400
com.dremio.exec.planner.sql.parser.impl.ParserImpl.SqlStmt():891
com.dremio.exec.planner.sql.parser.impl.ParserImpl.SqlStmtEof():903
com.dremio.exec.planner.sql.parser.impl.ParserImpl.parseSqlStmtEof():192
com.dremio.exec.planner.sql.parser.impl.ParserWithCompoundIdConverter.parseSqlStmtEof():59
org.apache.calcite.sql.parser.SqlParser.parseQuery():131
org.apache.calcite.sql.parser.SqlParser.parseStmt():163
com.dremio.exec.planner.sql.SqlConverter.parse():180
com.dremio.exec.planner.sql.handlers.commands.CommandCreator.getSqlCommand():249
com.dremio.exec.planner.sql.handlers.commands.CommandCreator.toCommand():205
com.dremio.exec.work.foreman.AttemptManager.run():282
java.util.concurrent.ThreadPoolExecutor.runWorker():1149
java.util.concurrent.ThreadPoolExecutor$Worker.run():624
java.lang.Thread.run():748
```

---

<div class="post-metadata">

**Author:** ![abhba](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@abhba](https://community.dremio.com/u/abhba)\
**Post date:** [April 25, 2019, 5:31am UTC](https://community.dremio.com/t/connecting-dremio-with-python-using-jdbc/3239/9 "2019-04-25T05:31:05Z")

</div>

[fbb7e22a-05b2-4ebc-88ee-1a580b68e1a9.zip](https://us1.discourse-cdn.com/flex020/uploads/dremio/original/2X/4/4776760c4a86c841b1e450a537a69b264e450472.zip) (4.9 KB)

this is the profile of the job .Which I ran

---

<div class="post-metadata">

**Author:** ![laurent](https://sea2.discourse-cdn.com/flex020/user_avatar/community.dremio.com/laurent/32/16_2.png) [@laurent](https://community.dremio.com/u/laurent)\
**Post date:** [April 25, 2019, 6:05am UTC](https://community.dremio.com/t/connecting-dremio-with-python-using-jdbc/3239/10 "2019-04-25T06:05:27Z")

</div>

If you look at your profile in the UI, you will see that the query looks like a lot like your python script instead of just the `SHOW DATABASES` statement, so my guess is that your zeppelin script should look like:

```auto
%jdbc(dremio)
SHOW DATABASES

```

---

<div class="post-metadata">

**Author:** ![abhba](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@abhba](https://community.dremio.com/u/abhba)\
**Post date:** [April 25, 2019, 9:16am UTC](https://community.dremio.com/t/connecting-dremio-with-python-using-jdbc/3239/11 "2019-04-25T09:16:18Z")

</div>

Hi Laurent,  
you are correct I can run the queries like this in zeppelin but I want the python to connect with dremio so that I can use python libraries to query dremio .

---

<div class="post-metadata">

**Author:** ![laurent](https://sea2.discourse-cdn.com/flex020/user_avatar/community.dremio.com/laurent/32/16_2.png) [@laurent](https://community.dremio.com/u/laurent)\
**Post date:** [April 25, 2019, 3:48pm UTC](https://community.dremio.com/t/connecting-dremio-with-python-using-jdbc/3239/12 "2019-04-25T15:48:31Z")

</div>

Not an expert at Zeppelin, but in that case, shouldn’t you start your script with `%python` instead of `%jdbc(dremio)` according to [https://zeppelin.apache.org/docs/0.8.0/interpreter/python.html](https://zeppelin.apache.org/docs/0.8.0/interpreter/python.html)?

---

<div class="post-metadata">

**Author:** ![abhba](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@abhba](https://community.dremio.com/u/abhba)\
**Post date:** [April 26, 2019, 3:55am UTC](https://community.dremio.com/t/connecting-dremio-with-python-using-jdbc/3239/13 "2019-04-26T03:55:17Z")

</div>

Correct Laurent .But for that you need to add a python interpreter and In my case I m using JDBC interpreter to query dremio not Python interpreter .So I don’t think it is needed .

---

<div class="post-metadata">

**Author:** ![laurent](https://sea2.discourse-cdn.com/flex020/user_avatar/community.dremio.com/laurent/32/16_2.png) [@laurent](https://community.dremio.com/u/laurent)\
**Post date:** [April 26, 2019, 4:08pm UTC](https://community.dremio.com/t/connecting-dremio-with-python-using-jdbc/3239/14 "2019-04-26T16:08:42Z")

</div>

Like I said, not an expert using Zeppelin, but if you use `%jdbc(...)`, the remaining of the script should be a SQL statement. If you use `%python`, then the remaining of the script should be some python code. I don’t think you can have `%jdbc` with python code.

As far as I can tell, the JDBC driver works as expected, so I would suggest to contact the Zeppelin community ([https://zeppelin.apache.org/community.html](https://zeppelin.apache.org/community.html)) to get more guidance on your use-case.
