1

I'm trying to setup a way to execute SQL queries on GraphDB pre-configured JDBC tables. I got it to work using a SQL engine like SQuirrel SQL Client, but so far I have not been successful in Python. I tried using the python package jaydebeapi, but I'm getting an error that my class GraphDB localhost is not found.

Does anybody have experience with using this python package - especially in combination with Ontotext GraphDB, or alternatives, and can give some tips in the right direction?

import jaydebeapi

# JDBC connection details
jdbc_url = "jdbc:graphdb:url=http://localhost:7200"
driver_class = "com.ontotext.graphdb.jdbc.remote.Driver"
driver_jar = "C:/Users/franken/Desktop/squirrelSQL/plugins/graphdb-jdbc-remote-10.0.0.jar"  # Replace with the path to your GraphDB JDBC driver jar file
alias_name = "GraphDB localhost"

# SQL query to execute
sql_query = "SELECT * FROM GRAPHDB.IMAGINGBACKUPS.SOFTWARE" 

# Establish connection
with jaydebeapi.connect(jclassname=alias_name, url=jdbc_url, driver_args=None, jars=driver_jar, libs=None) as conn:
    with conn.cursor() as curs:
        curs.execute(sql_query)
        curs.fetchall()

Error I receive:

(jdbc-py3.12) PS C:\Users\franken\jdbc\jdbc> python usesql.py
Traceback (most recent call last):
  File "C:\Users\franken\jdbc\jdbc\usesql.py", line 13, in <module>
    with jaydebeapi.connect(jclassname=alias_name, url=jdbc_url, driver_args=None, jars=driver_jar, libs=None) as conn:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\franken\jdbc\.venv\Lib\site-packages\jaydebeapi\__init__.py", line 412, in connect
    jconn = _jdbc_connect(jclassname, url, driver_args, jars, libs)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\franken\jdbc\.venv\Lib\site-packages\jaydebeapi\__init__.py", line 221, in _jdbc_connect_jpype
    jpype.JClass(jclassname)
  File "C:\Users\franken\jdbc\.venv\Lib\site-packages\jpype\_jclass.py", line 99, in __new__
    return _jpype._getClass(jc)
           ^^^^^^^^^^^^^^^^^^^^
TypeError: Class GraphDB localhost is not found

Note, I get a similar, but not exactly the same error 'java.lang.java.lang.NoClassDefFoundError: java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory' error when I change the jclassname to driver_class.

(jdbc-py3.12) PS C:\Users\franken\jdbc\jdbc> python usesql.py
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Traceback (most recent call last):
  File "ClassLoader.java", line 521, in java.lang.ClassLoader.loadClass
java.lang.java.lang.ClassNotFoundException: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "org.jpype.JPypeContext.java", line -1, in org.jpype.JPypeContext.callMethod
Exception: Java Exception

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\franken\jdbc\jdbc\usesql.py", line 13, in <module>
    with jaydebeapi.connect(jclassname=driver_class, url=jdbc_url, driver_args=None, jars=driver_jar, libs=None) as conn:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\franken\jdbc\.venv\Lib\site-packages\jaydebeapi\__init__.py", line 412, in connect
    jconn = _jdbc_connect(jclassname, url, driver_args, jars, libs)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\franken\jdbc\.venv\Lib\site-packages\jaydebeapi\__init__.py", line 230, in _jdbc_connect_jpype
    return jpype.java.sql.DriverManager.getConnection(url, *dargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
java.lang.java.lang.NoClassDefFoundError: java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.