1 推荐使用 jdbc 连接。
上代码:
jarpath = "%s/%s" % (os.path.dirname(os.path.realpath(__file__)), "jar/db2jcc4.jar")
jarpath2 = "%s/%s" % (os.path.dirname(os.path.realpath(__file__)), "jar/db2java.jar")
jarpath3 = "%s/%s" % (os.path.dirname(os.path.realpath(__file__)), "jar/db2jcc_license_cu.jar")
driver, driver_args = 'com.ibm.db2.jcc.DB2Driver', \
['jdbc:db2://%s:%d/%s' % (jxnxsmartapi.jxconfig.hostname, jxnxsmartapi.jxconfig.port,
jxnxsmartapi.jxconfig.databasename),
jxnxsmartapi.jxconfig.user, jxnxsmartapi.jxconfig.password]
dburl = 'jdbc:db2://%s:%d/%s' % (jxnxsmartapi.jxconfig.hostname, jxnxsmartapi.jxconfig.port,
jxnxsmartapi.jxconfig.databasename)
conn = jaydebeapi.connect('com.ibm.db2.jcc.DB2Driver', dburl,
[jxnxsmartapi.jxconfig.user, jxnxsmartapi.jxconfig.password],
[jarpath, jarpath2, jarpath3])
2 如果在django中使用。请加
if jpype.isJVMStarted() and not jpype.isThreadAttachedToJVM():
jpype.attachThreadToJVM()
jpype.java.lang.Thread.currentThread().setContextClassLoader(
jpype.java.lang.ClassLoader.getSystemClassLoader())