Search code examples
pythonjavajdbcsybasejaydebeapi

jaydebeapi.connect always returning: "TypeError: Class sajdbc4.jar is not found"


I am trying to use the jaydebeapi python package to create a jdbc database connection, but no matter what argument I put in the connect method I get the same error: "TypeError: Class [first_argurment_str] is not found"

import jaydebeapi

conn = jaydebeapi.connect('sajdbc4.jar', connectionString,[userName, Password])

I tried adding jar files to the directory, and referring directly to the paths in $CLASSPATH neither changed the error.

Originally, I was trying to connect to a Sybase database, but I'd settle for anything at this point.

Full Error Text:

    File "H:\Data-Sources\Connection-Examples\Sybase\jayBeaOnly.py", line 2, in <module>
    conn = jaydebeapi.connect("org.hsqldb.jdbcDriver",
    File "C:\Users\username\AppData\Roaming\Python\Python39\site-packages\jaydebeapi\__init__.py", line 412, in connect
    jconn = _jdbc_connect(jclassname, url, driver_args, jars, libs)
    File "C:\Users\username\AppData\Roaming\Python\Python39\site-packages\jaydebeapi\__init__.py", line 221, in _jdbc_connect_jpype
jpype.JClass(jclassname)
    File "C:\Users\username\AppData\Roaming\Python\Python39\site-packages\jpype\_jclass.py", line 99, in __new__
return _jpype._getClass(jc)
    TypeError: Class org.hsqldb.jdbcDriver is not found

python 3.9;

Windows 10;

JayDeBeApi 1.2.3;

openjdk version "1.8.0_332"


Solution

  • I fixed the problem by adding several file paths to the $CLASSPATH variable and ensuring that the environment variables were present in the script. Ultimately, I needed more than one file added to $CLASSPATH. Solution below (your file paths will obviously differ)

    os.environ['Path'] = os.environ['Path']+f';D:\\Users\\{user}\\Sybase\\IQ-16_0\\Bin32'
    os.environ['JAVA_HOME'] = 'C:\\Program Files\\Microsoft\\jdk-11.0.15.10-hotspot'
    os.environ['CLASSPATH'] = (f'D:\\Users\\{user}\\Sybase\\IQ-16_0\\Java\\sajdbc4.jar;'+
    f'D:\\Users\\{user}\\Sybase\\IQ-16_0\\Bin32\\dbjdbc16.dll;'+
    f'D:\\Users\\{user}\\Sybase\\jConnect-7_0\\classes\\jconn4.jar;'+
    f'D:\\Users\\{user}\\Sybase\\jConnect-7_0\\devclasses\\jconn4.jar')