【发布时间】:2020-12-11 03:27:24
【问题描述】:
我正在尝试从 Python 提示符并使用 JayDeBeApi 连接到 MySQL 数据库。下面是我正在使用的一段代码:
"**Python 2.7.16 (default, Oct 10 2019, 22:02:15)
[GCC 8.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import jpype
>>> import jaydebeapi
>>> import os
>>> jar = "/tmp/:/usr/share/java/"
>>> os.environ['JAVA_HOME'] ="/usr/lib/jvm/adoptopenjdk-8-hotspot-amd64"
>>> os.environ['CLASSPATH'] =jar
>>> args='-Djava.class.path=%s' % jar
>>> jvm_path = jpype.getDefaultJVMPath()
>>> jpype.startJVM(jvm_path, args)
/home/aarpan_roy/.local/lib/python2.7/site-packages/jpype/_core.py:218: UserWarning:
-------------------------------------------------------------------------------
Deprecated: convertStrings was not specified when starting the JVM. The default
behavior in JPype will be False starting in JPype 0.8. The recommended setting
for new code is convertStrings=False. The legacy value of True was assumed for
this session. If you are a user of an application that reported this warning,
please file a ticket with the developer.
-------------------------------------------------------------------------------
""")
>>> database_host='<MySQL DB HOST>'
>>> database_user='<MySQL DB USER>'
>>> database_password='<MySQL DB PASSWORD>'
>>> database_port='<MySQL DB PORT>'
>>> database_db='<MySQL DB DATABASE>'
>>> jclassname = "com.mysql.jdbc.Driver"
>>> url = "jdbc:mysql://{host}:{port}/{database}".format(host=database_host, port=database_port, database=database_db)
>>> driver_args = [url, database_user, database_password]
>>> jars = ["/tmp/mysql-connector-java-5.1.45.jar","/usr/share/java/mysql.jar"]
>>> libs = None
>>> cnx = jaydebeapi.connect(jclassname, url, driver_args, jars=jars, libs=libs)**
但是,我遇到了以下错误:
“回溯(最近一次通话最后一次):
文件“”,第 1 行,在
连接中的文件“
您能否帮助我了解我在哪里遗漏了什么以及这里需要纠正什么? 提前致谢。
【问题讨论】:
标签: python mysql jpype jaydebeapi