我正试图使用jaydebeapi python包来创建jdbc数据库连接,但无论我在connect
方法中放入什么参数,我都会得到相同的错误:"类型错误:找不到类[first_argurment_str]">
import jaydebeapi
conn = jaydebeapi.connect('sajdbc4.jar', connectionString,[userName, Password])
我尝试将jar文件添加到目录中,并直接引用$CLASSPATH
中的路径,这都没有改变错误。
最初,我试图连接到Sybase数据库,但现在我已经满足了。
完整错误文本:
File "H:Data-SourcesConnection-ExamplesSybasejayBeaOnly.py", line 2, in <module>
conn = jaydebeapi.connect("org.hsqldb.jdbcDriver",
File "C:UsersusernameAppDataRoamingPythonPython39site-packagesjaydebeapi__init__.py", line 412, in connect
jconn = _jdbc_connect(jclassname, url, driver_args, jars, libs)
File "C:UsersusernameAppDataRoamingPythonPython39site-packagesjaydebeapi__init__.py", line 221, in _jdbc_connect_jpype
jpype.JClass(jclassname)
File "C:UsersusernameAppDataRoamingPythonPython39site-packagesjpype_jclass.py", line 99, in __new__
return _jpype._getClass(jc)
TypeError: Class org.hsqldb.jdbcDriver is not found
python 3.9;
Windows 10;
JayDeBeApi 1.2.3;
openjdk版本";1.8.0_332";
我通过向$CLASSPATH
变量添加几个文件路径并确保脚本中存在环境变量来解决问题。最终,我需要将多个文件添加到$CLASSPATH
中。以下解决方案(您的文件路径明显不同(
os.environ['Path'] = os.environ['Path']+f';D:\Users\{user}\Sybase\IQ-16_0\Bin32'
os.environ['JAVA_HOME'] = 'C:\Program Files\Microsoft\jdk-11.0.15.10-hotspot'
os.environ['CLASSPATH'] = (f'D:\Users\{user}\Sybase\IQ-16_0\Java\sajdbc4.jar;'+
f'D:\Users\{user}\Sybase\IQ-16_0\Bin32\dbjdbc16.dll;'+
f'D:\Users\{user}\Sybase\jConnect-7_0\classes\jconn4.jar;'+
f'D:\Users\{user}\Sybase\jConnect-7_0\devclasses\jconn4.jar')
对我来说,解决方案是将jconn4.jar复制到"lt;JAVA_HOME>jre/lib/ext";