Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connect to DB2 via JayDeBeApi JDBC in Python

I've been struggling for a while to connect to DB2 via Python client on OSX (maveriks). A valid option seem to be using JayDeBeApi but, running the following code...

import jaydebeapi
import jpype

jar = '/opt/IBM/db2/V10.1/java/db2jcc4.jar' # location of the jdbc driver jar
args='-Djava.class.path=%s' % jar
jvm = jpype.getDefaultJVMPath()
jpype.startJVM(jvm, args)

jaydebeapi.connect('com.ibm.db2.jcc.DB2Driver',
'jdbc:db2://server:port/database','myusername','mypassword')

I'll get the following error

Traceback (most recent call last):
  File "<pyshell#67>", line 2, in <module>
    'jdbc:db2://server:port/database','myusername','mypassword')
  File "/Library/Python/2.7/site-packages/jaydebeapi/dbapi2.py", line 269, in connect
    jconn = _jdbc_connect(jclassname, jars, libs, *driver_args)
  File "/Library/Python/2.7/site-packages/jaydebeapi/dbapi2.py", line 117, in _jdbc_connect_jpype
    return jpype.java.sql.DriverManager.getConnection(*driver_args)
com.ibm.db2.jcc.am.SqlSyntaxErrorExceptionPyRaisable: com.ibm.db2.jcc.am.SqlSyntaxErrorException: [jcc][t4][10205][11234][3.63.123] Null userid is not supported. ERRORCODE=-4461, SQLSTATE=42815

So basically I'm connecting to the server, but for some reason I'm not using the username & password provided. Any idea on how to pass correctly username and password? I can't find further specification for this problem exactly, and any suggestion or tips are welcome.

like image 373
Alessandro Mariani Avatar asked Feb 13 '23 03:02

Alessandro Mariani


1 Answers

nevermind... I wasn't passing the LIST of parameters.... with the following changes it now works:

jaydebeapi.connect(
    'com.ibm.db2.jcc.DB2Driver', 
    ['jdbc:db2://server:port/database','myusername','mypassword']
)
like image 66
Alessandro Mariani Avatar answered Feb 16 '23 03:02

Alessandro Mariani