I want to run SQL on an IBM i database from python, with jpype and jdbc. The problem I have must be from jpype, all seems correct (the informations that I print from my program), but I have a "ClassNotFoundException'. I downloaded and installed in my folder IBM's jar (jt400-20.0.6.jar) Then I ran this simple test
import os
import jpype
import jpype.dbapi2
driver_file_path = os.path.join(os.path.dirname(__file__), "jt400-20.0.6.jar")
jpype.startJVM()
print('startJVM effectué')
jpype.addClassPath(driver_file_path)
class_path = jpype.getClassPath(True)
print("Class Path " + class_path)
jpype.java.lang.System.out.println("hello world")
connection_string = 'jdbc:as400://MACHINE'
try:
cnx = jpype.dbapi2.connect(connection_string, driver= "com.ibm.as400.access.AS400JDBCDriver",
driver_args={
"user": 'UTIL',
"password": 'MOTPASSE',
"extended metadata": "true",
}
)
except jpype.dbapi2.Error as err:
print("Erreur" + err)
The driver exists at the driver_file_path that is printed. There's an AS400JDBCDriver.class in com\ibm\as400\access in the jar file (I opened the file with 7 zip to see it) When running, I have this informations
startJVM effectué
Class Path C:\Users...\jt400-20.0.6.jar
hello world
So the path should have been added to the jvm, and java is working... But I have also
Traceback (most recent call last):
File "org.jpype.JPypeContext.java", line -1, in org.jpype.JPypeContext.callMethod
Exception: Java Exception
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\...\Test_jpype_question.py", line 37, in <module>
cnx = jpype.dbapi2.connect(connection_string, driver= "com.ibm.as400.access.AS400JDBCDriver",
File "C:\...\jpype\dbapi2.py", line 404, in connect
_jpype.JClass('java.lang.Class').forName(driver).newInstance()
java.lang.java.lang.ClassNotFoundException: java.lang.ClassNotFoundException: com.ibm.as400.access.AS400JDBCDriver
I tried lot of things, but I can't understand what's wrong. What can I do to make it work?