1

I have to connect to a DB2 to extract some data and create a Tableau Data Extract, in order to do this I wanted to use JayDeBeApi, and to test it I was trying to connect myself to a small Postgres database, but I can't establish a proper connection to it because it throws me all the time the following error:

jpype._jexception.RuntimeExceptionPyRaisable: java.lang.RuntimeException: Class org.postgresql.Driver not found

My current implementation is this

import jaydebeapi as jdbc

sql = 'Select * From world.city'
postgresql_class = 'org.postgresql.Driver'
postgresql_jdbc_path = 'path/to/postgresql-42.2.4.jar'
postgresql_url = 'jdbc:postgresql://host:port/database'
postgresql_user = 'user'
postgresql_pw = 'pass'

conn = jdbc.connect(postgresql_class, 
                    [postgresql_url, postgresql_user, postgresql_pw], 
                    postgresql_jdbc_path)

curs = conn.cursor()

curs.execute('SELECT * FROM csv_reports LIMIT 2')
curs.fetchall()
curs.close()
conn.close()

Does anyone know what class do I have to specify in order to make this work? Or how do i have to specify the jdbc path so that JayDeBeApi can use the class or something

sgaseretto
  • 421
  • 5
  • 13

1 Answers1

1

According to the JayDeBeApi documentation

The first argument to connect is the name of the Java driver class. The second argument is a string with the JDBC connection URL. Third you can optionally supply a sequence consisting of user and password or alternatively a dictionary containing arguments that are internally passed as properties to the Java DriverManager.getConnection method. See the Javadoc of DriverManager class for details.

So you shouldn't be including the connection URL in the list with the username and password; it should be on its own as the second argument:

jdbc.connect(postgresql_class, 
             postgresql_url, 
             [postgresql_user, postgresql_pw], 
             postgresql_jdbc_path)
Gord Thompson
  • 116,920
  • 32
  • 215
  • 418