Connect to JDBC python

Viewed 48

I am try to connect to my gaussdb or even postgressql using in python jaydebeapi from linux and i keep get error

Class name not found

I copy my jar file to /usr/lib/jvm/java-11-openjdk-amd46/lib/com.driver.jar

is there something else ?

‘’’

import jaydebeapi import sys jaydebeapi.connect("com.gauss.Driver", url, [username, password], "./file-jdbc.jar")

Erorr Class com.gauss.driver not found ‘’’

1 Answers

You can try to explicitly start a JVM and pass it the fullpath of your driver jar file:


import jaydebeapi
import jpype

jpype.startJVM(jpype.getDefaultJVMPath(),
                   f"-Djava.class.path=/usr/lib/jvm/java-11-openjdk-amd46/lib/com.driver.jar")


jaydebeapi.connect("com.gauss.Driver", url, [username, password], "/usr/lib/jvm/java-11-openjdk-amd46/lib/")

If you're using postgresSQL databases I would also suggest you to take a look to the psycopg library:

https://pypi.org/project/psycopg/

https://www.geeksforgeeks.org/introduction-to-psycopg2-module-in-python/

Related