jaydebeapi icon indicating copy to clipboard operation
jaydebeapi copied to clipboard

How do I connect to db2 on z/os?

Open rush4ratio opened this issue 8 years ago • 4 comments

I get this error: java.sql.SQLExceptionPyRaisable: com.ibm.db2.jcc.am.SqlSyntaxErrorException: [jcc][t4][10205][11234][3.71.22] Null userid is not supported. ERRORCODE=-4461, SQLSTATE=42815

Not only am I to pass the usual jar file but there's an additional one for the license.

rush4ratio avatar Jun 15 '17 17:06 rush4ratio

This works for the first connect string, LUW or zOS should not matter with a type4 driver. Your license file jar would have to be one for DB2 Connect. The server/port would also be the DB2 Connect you are using. This is Windows Python. Linux uses a different format for jaydebeapi parm.

`p8_dbs_connect_urls = [['d','jdbc:db2://r0007qn0v.bnymellon.net:3600/DDTFSIBF:user=ibfm55m;password={0:s};sslConnection=false;'], ['d','jdbc:db2://r0007qn0v.bnymellon.net:3602/DDTFSIBF:user=ibfm55m;password={0:s};sslConnection=false;'], ['d','jdbc:db2://l2u7.bnymellon.net:3600/DUTFSIBF:user=ibfm55m;password={0:s};sslConnection=false;'], ['p','jdbc:db2://l2p7.bnymellon.net:3600/DPTFSIBF:user=ibfm15m;password={0:s};sslConnection=false;']]

jardb2 = [os.path.join(os.path.split(os.path.realpath(file))[0],"db2jcc4.jar"), os.path.join(os.path.split(os.path.realpath(file))[0],"db2jcc_license_cu.jar")] drvdb2 = "com.ibm.db2.jcc.DB2Driver" conn = [] for ix,dbs_conn_url in enumerate(p8_dbs_connect_urls): logging.info("connect %s entry %d",str(datetime.now()),ix) try: conn.append(jaydebeapi.connect(drvdb2, dbs_conn_url[1].format(pwd if dbs_conn_url[0] == 'd' else pwp), jars=jardb2)) logging.info("close %s",str(datetime.now())) conn[ix].close() except (Exception) as e: logging.error(e) `

EdLipson5117 avatar Sep 28 '17 15:09 EdLipson5117

For future reference:

import jaydebeapi as jdba
import jpype #jdba uses jpype, but for me it only worked if I set up the jvm via jpype directly

jar = 'path/to/db2jcc4.jar'
lic = 'path/to/db2jcc_license.jar'
jvm = jpype.getDefaultJVMPath() # obviously java needs to be installed
jpype.startJVM(jvm, '-Djava.class.path={}:{}'.format(jar, lic))

user= 'username'
pw = "password123"
conn = jdba.connect('com.ibm.db2.jcc.DB2Driver', 'jdbc:db2://SERVER:PORT/DATABASE', [user, pw])

ltOgt avatar Aug 01 '18 07:08 ltOgt

Even with @ltOgt's snippet this did not work for me. What am I doing wrong? Thanks! Of course I adjusted the paths to .jar and licence.jar files to absolute paths with /.

mondaysunrise avatar May 18 '20 14:05 mondaysunrise

I was able to establish and test a connection to DB2 on z/OS using the information provided here. Using a process of elimination for similar issues below.

  1. Verify File paths.
    import os.path from os import path path.exists(lic) True <-- Python Output path.exists(jar) True <-- Python Output
  2. Correct JDBC connections string. Colon : after the database name, all parameters end with a semicolon ; 'jdbc:db2://server:port/database:sslConnection=true;'

mkhouse8 avatar Mar 03 '22 17:03 mkhouse8