baztian / jaydebeapi

JayDeBeApi module allows you to connect from Python code to databases using Java JDBC. It provides a Python DB-API v2.0 to that database.
GNU Lesser General Public License v3.0
366 stars 148 forks source link

IBM DB2Driver not found #22

Closed wzymaster closed 7 years ago

wzymaster commented 8 years ago

I am trying this in my Python notebook in Jupyter 3.0 and unfortunately, it always complains that an error like :

---------------------------------------------------------------------------
java.lang.RuntimeExceptionPyRaisable      Traceback (most recent call last)
<ipython-input-5-b9bc6451129e> in <module>()
----> 1 idadb=IdaDataBase(dsn=connection_string)

/usr/local/lib/python2.7/dist-packages/ibmdbpy/base.pyc in __init__(self, dsn, uid, pwd, autocommit, verbose)
    239 
    240             try:
--> 241                 self._con = jaydebeapi.connect('com.ibm.db2.jcc.DB2Driver', self._connection_string)
    242             except:
    243                 raise

/usr/local/lib/python2.7/dist-packages/jaydebeapi/__init__.pyc in connect(jclassname, driver_args, jars, libs)
    357     else:
    358         libs = []
--> 359     jconn = _jdbc_connect(jclassname, jars, libs, *driver_args)
    360     return Connection(jconn, _converters)
    361 

/usr/local/lib/python2.7/dist-packages/jaydebeapi/__init__.pyc in _jdbc_connect_jpype(jclassname, jars, libs, *driver_args)
    180             return jpype.JArray(jpype.JByte, 1)(data)
    181     # register driver for DriverManager
--> 182     jpype.JClass(jclassname)
    183     return jpype.java.sql.DriverManager.getConnection(*driver_args)
    184 

/usr/local/lib/python2.7/dist-packages/jpype/_jclass.pyc in JClass(name)
     53     jc = _jpype.findClass(name)
     54     if jc is None:
---> 55         raise _RUNTIMEEXCEPTION.PYEXC("Class %s not found" % name)
     56 
     57     return _getClassFor(jc)

java.lang.RuntimeExceptionPyRaisable: java.lang.RuntimeException: Class com.ibm.db2.jcc.DB2Driver not found

Here is my source code:

import jaydebeapi
from ibmdbpy import IdaDataBase
connection_string="jdbc:db2://awh-yp-small03.services.dal.bluemix.net:50000/BLUDB:user=dash104434;password=xxxxxx;;"
idadb=IdaDataBase(dsn=connection_string)

It seems like that JayDeBeApi has problem to retrieve DB2 driver class, however, this jar file is actually in presence at '/usr/local/lib/db2jcc4.jar'.

However, if I manually inject a line of "jaydebeapi.connect('com.ibm.db2.jcc.DB2Driver', connection_string,'/usr/local/lib/db2jcc4.jar')" like the below, everything works fine :

import jaydebeapi
from ibmdbpy import IdaDataBase
connection_string="jdbc:db2://awh-yp-small03.services.dal.bluemix.net:50000/BLUDB:user=dash104434;password=xxxxxx;;"
jaydebeapi.connect('com.ibm.db2.jcc.DB2Driver', connection_string,'/usr/local/lib/db2jcc4.jar')
idadb=IdaDataBase(dsn=connection_string)

I am just wondering why db2 driver can't be recognized by default unless I explicitly invoke jaydebeapi.connect() function. Why ?

BazzalSeed commented 7 years ago

have similar problem

genomics-geek commented 7 years ago

I have the same problem as well

agorostidi commented 7 years ago

My case is worse... :-( Although I have JRE installed and the library on the CLASSLIB path, the JDBC driver it is not found and I always have an exception.... I also try to use jaydebeapi.connect, but then I do have the following error:

Traceback (most recent call last): File "./dash.py", line 23, in jaydebeapi.connect('com.ibm.db2.jcc.DB2Driver', connection_string,'/usr/src/app/db2jcc4.jar') File "/usr/local/lib/python2.7/site-packages/jaydebeapi/init.py", line 380, in connect jconn = _jdbc_connect(jclassname, url, driver_args, jars, libs) File "/usr/local/lib/python2.7/site-packages/jaydebeapi/init.py", line 190, in _jdbc_connect_jpype jpype.JClass(jclassname) File "/usr/local/lib/python2.7/site-packages/jpype/_jclass.py", line 55, in JClass raise _RUNTIMEEXCEPTION.PYEXC("Class %s not found" % name) jpype._jexception.RuntimeExceptionPyRaisable: java.lang.RuntimeException: Class com.ibm.db2.jcc.DB2Driver not found

baztian commented 7 years ago

Don't know the ibmdbpy module. Please report the problem there. Jaydebeapi as all other db api drivers always requires you to call connect before using it.

genomics-geek commented 7 years ago

I fixed this issue by passing the url. I used to not be able to connect and would get the following error:

java.lang.RuntimeExceptionPyRaisable: java.lang.RuntimeException: Class com.ibm.db2.jcc.DB2Driver not found

Here is an example:

jdbc_driver_name = 'com.ibm.db2.jcc.DB2Driver'
jdbc_driver_loc = 'path/to/db2jcc4.jar'
url = '{0}:user={1};password={2};;'.format(host, login, psw)

conn = jaydebeapi.connect(jclassname=jdbc_driver_name, url=url, jars=jdbc_driver_loc)
dj-falkson-lmnd commented 7 years ago

I'm still having this issue and am really stumped. I've tried passing the url like genomics-geek above and I've tried keeping the url separate from the driver_args. The weird thing is that I am able to use these connection parameters exactly in R and it works, so why wouldn't it in Python?

EDIT: my computer was logged off over night. Upon logging back in, I am able to establish the JDBC connection. I'm not sure why that is.

baztian commented 7 years ago

Please post a code snippet

Am 28.02.2017 1:59 vorm. schrieb "dfalkson" notifications@github.com:

I'm still having this issue and am really stumped. I've tried passing the url like genomics-geek above and I've tried keeping the url separate from the driver_args. The weird thing is that I am able to use these connection parameters exactly in R and it works, so why wouldn't it in Python?

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/baztian/jaydebeapi/issues/22#issuecomment-282907826, or mute the thread https://github.com/notifications/unsubscribe-auth/ACWQrV7wzm1Xpc3jrvWML5MoB86tUdoZks5rg3F_gaJpZM4HuKnP .

georg90 commented 6 years ago

I have the same problem, any fix for jupyter? The code works great in a native python script, but fails within my notebook.

$ jupyter-notebook --version
5.6.0
$ python3 --version
Python 3.7.0
import jaydebeapi
import sys,os,os.path

conn = 'jdbc:db2://host:port/db:sslConnection=true;sslTrustStoreLocation=ertTrustStore;sslTrustStorePassword=jgjgjg;'
class_name = 'com.ibm.db2.jcc.DB2Driver'
sql = 'Select * table A fetch first 100 rows only'
login = ['user','pass']
jars = 'db2java/db2jcc4.jar'
conn = jaydebeapi.connect(class_name, conn, login, jars)

jars is within the same directory as the notebook. But still, this code won't work in jupyer notebook.

Any ideas?

chris-ratcliffe commented 6 years ago

@baztian , I am also seeing a failure running inside a Jupyter notebook vs a standalone python script where it works fine. I can't seem to figure out the difference. Here is the code run in the notebook:

# create JDBC connection to the netezza database
import jaydebeapi

!echo 'JAVA_HOME: '$JAVA_HOME
print("Driver name: " + driverName + "\nDriver path: " + driverFileName)
!ls -altr $driverFileName
!ls -daltr $driverDir
print("jaydebeapi version: " + jaydebeapi.__version__)

mpwconn = jaydebeapi.connect(jclassname=driverName, url=connectionString, driver_args={'user': uid, 'password': pwd},jars=driverFileName)

JAVA_HOME: /opt/ibm/java-x86_64-80
Driver name: org.netezza.Driver
Driver path: /home/dsxuser/drivers/nzjdbc-3.jar
-rwxr-xr-x 1 dsxuser dsxuser 359254 Oct 16 16:55 /home/dsxuser/drivers/nzjdbc-3.jar
drwxr-xr-x 2 dsxuser dsxuser 4096 Oct 16 15:09 /home/dsxuser/drivers
jaydebeapi version: 1.1.1

---------------------------------------------------------------------------
java.lang.RuntimeExceptionPyRaisable      Traceback (most recent call last)
<ipython-input-37-03b494b3284a> in <module>()
     11 #!md5sum $driverFileName
     12 
---> 13 mpwconn = jaydebeapi.connect(jclassname=driverName, url=connectionString, driver_args={'user': uid, 'password': pwd},jars=driverFileName)
     14 
     15 curs = mpwconn.cursor()

/opt/conda/envs/DSX-Python35/lib/python3.5/site-packages/jaydebeapi/__init__.py in connect(jclassname, url, driver_args, jars, libs)
    379     else:
    380         libs = []
--> 381     jconn = _jdbc_connect(jclassname, url, driver_args, jars, libs)
    382     return Connection(jconn, _converters)
    383 

/opt/conda/envs/DSX-Python35/lib/python3.5/site-packages/jaydebeapi/__init__.py in _jdbc_connect_jpype(jclassname, url, driver_args, jars, libs)
    188             return jpype.JArray(jpype.JByte, 1)(data)
    189     # register driver for DriverManager
--> 190     jpype.JClass(jclassname)
    191     if isinstance(driver_args, dict):
    192         Properties = jpype.java.util.Properties

/opt/conda/envs/DSX-Python35/lib/python3.5/site-packages/jpype/_jclass.py in JClass(name)
     53     jc = _jpype.findClass(name)
     54     if jc is None:
---> 55         raise _RUNTIMEEXCEPTION.PYEXC("Class %s not found" % name)
     56 
     57     return _getClassFor(jc)

java.lang.RuntimeExceptionPyRaisable: java.lang.RuntimeException: Class org.netezza.Driver not found

curs = mpwconn.cursor()

Is there any other information that I can provide to shed some light on why it can't find the class?

sushmit86 commented 5 years ago

I am trying to connect to Netezza using the following code

import jaydebeapi
conn = jaydebeapi.connect(jclassname= "org.netezza.Driver",
                          url="jdbc:netezza://XXX.XXX.XXX.XXX:5480/DB",
                          driver_args=["sroy", "xxxx"],
                          jars= "/Users/roysu001/nzjdbc3.jar")

its giving me

java.lang.RuntimeExceptionPyRaisable      Traceback (most recent call last)
<ipython-input-29-fa62ef797f95> in <module>()
      2                           url="jdbc:netezza://159.127.220.71:5480/PSTPLRDMDB01",
      3                           driver_args=["stpl_sroy", "Euler_pi_3.14"],
----> 4                           jars= "/Users/roysu001/nzjdbc3.jar")

/anaconda3/lib/python3.7/site-packages/jaydebeapi/__init__.py in connect(jclassname, url, driver_args, jars, libs)
    379     else:
    380         libs = []
--> 381     jconn = _jdbc_connect(jclassname, url, driver_args, jars, libs)
    382     return Connection(jconn, _converters)
    383 

/anaconda3/lib/python3.7/site-packages/jaydebeapi/__init__.py in _jdbc_connect_jpype(jclassname, url, driver_args, jars, libs)
    188             return jpype.JArray(jpype.JByte, 1)(data)
    189     # register driver for DriverManager
--> 190     jpype.JClass(jclassname)
    191     if isinstance(driver_args, dict):
    192         Properties = jpype.java.util.Properties

/anaconda3/lib/python3.7/site-packages/jpype/_jclass.py in JClass(name)
     71     jc = _jpype.findClass(name)
     72     if jc is None:
---> 73         raise _RUNTIMEEXCEPTION.PYEXC("Class %s not found" % name)
     74 
     75     return _getClassFor(jc)

java.lang.RuntimeExceptionPyRaisable: java.lang.RuntimeException: Class org.netezza.Driver not found

I am on Python 3 and Mac @baztian any idea

mondaysunrise commented 4 years ago

I get the same error. How to fix this?