Jython 和Mysql - 目前的连接做法是什么?
第一次尝试 jython,因为工作中出现了一些非常适合它的东西。我假设 jython 可以使用 mysql jdbc 驱动程序建立 mysql jdbc 连接。然而,在谷歌搜索和阅读之后,我遇到了问题,它似乎是 jython 特定的,而且可能很简单。 所以我做 jython:
Jython 2.5.1 (Release_2_5_1:6813, Sep 26 2009, 13:47:54)
[Java HotSpot(TM) 64-Bit Server VM (Apple Inc.)] on java1.6.0_17
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print sys.path
['', '/JYTHONPATH/mysql-connector-java-5.1.10-bin.jar', '/WorkArea/Apps/jython/jython2.5.1/Lib', '__classpath__', '__pyclasspath__/', '/WorkArea/Apps/jython/jython2.5.1/Lib/site-packages']
>>>
我正在运行的代码
from java.lang import *
from java.sql import *
driverName="com.mysql.jdbc.Driver"
Class.forName(driverName)
url = "jdbc:mysql://localhost/test?user=jgreenaw&password="
con = DriverManager.getConnection(url)
stmt = con.createStatement()
输出
riux:Desktop$ jython pymysql.py
Traceback (most recent call last):
File "pymysql.py", line 7, in <module>
Class.forName(driverName)
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:315)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:330)
at java.lang.ClassLoader.loadClass(ClassLoader.java:250)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:398)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
java.lang.ClassNotFoundException: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
有什么建议吗?
谢谢
Just trying jython for the first time, because something came up at work that would fit for this perfect for it. I assume jython can make mysql jdbc connection using the mysql jdbc driver. After googling and reading, however I am having problems and it seems jython specific and probably simple.
so i do jython:
Jython 2.5.1 (Release_2_5_1:6813, Sep 26 2009, 13:47:54)
[Java HotSpot(TM) 64-Bit Server VM (Apple Inc.)] on java1.6.0_17
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print sys.path
['', '/JYTHONPATH/mysql-connector-java-5.1.10-bin.jar', '/WorkArea/Apps/jython/jython2.5.1/Lib', '__classpath__', '__pyclasspath__/', '/WorkArea/Apps/jython/jython2.5.1/Lib/site-packages']
>>>
code i'm running
from java.lang import *
from java.sql import *
driverName="com.mysql.jdbc.Driver"
Class.forName(driverName)
url = "jdbc:mysql://localhost/test?user=jgreenaw&password="
con = DriverManager.getConnection(url)
stmt = con.createStatement()
output
riux:Desktop$ jython pymysql.py
Traceback (most recent call last):
File "pymysql.py", line 7, in <module>
Class.forName(driverName)
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:315)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:330)
at java.lang.ClassLoader.loadClass(ClassLoader.java:250)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:398)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
java.lang.ClassNotFoundException: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
any advice?
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您有权读取该 .jar 吗?在您的代码中尝试将其作为文件打开。另请检查此文件是否是包含 com/mysql/jdbc/Driver.class 的有效
jar
存档。当我在 Windows 上使用 PostgreSQL 时,我可以通过以下方式检查它:
Do you have rights to read that .jar? In your code try to open it as file. Also check if this file is valid
jar
archive that containscom/mysql/jdbc/Driver.class
.While I use PostgreSQL on Windows I can check it with:
将 mysql-connector-java-5.1.10-bin.jar 添加到 CLASSPATH 环境变量,而不仅仅是 JYTHONPATH 环境变量。
Add mysql-connector-java-5.1.10-bin.jar to the CLASSPATH environment variable, not just the JYTHONPATH environment variable.