Jython CLASSPATH、sys.path 和 JDBC 驱动程序

编程入门 行业动态 更新时间:2024-10-27 06:30:03
本文介绍了Jython CLASSPATH、sys.path 和 JDBC 驱动程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如何在运行时将 JDBC 驱动程序添加到 Jython?使用 CLASSPATH 有效,但使用 sys.path 不适用于 zxJDBC,即使该类导入良好并且可以从 Jython 解释器提示符进行操作.

How can I add JDBC drivers at runtime to Jython? Using CLASSPATH works, but using sys.path doesn't work with zxJDBC even though the class is imported fine and can be manipulated from the Jython interpreter prompt.

为什么这样做:

$ CLASSPATH=/tmp/jtds-1.2.5.jar ./jython *sys-package-mgr*: processing new jar, '/private/tmp/jtds-1.2.5.jar' 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_20 Type "help", "copyright", "credits" or "license" for more information. >>> from java.lang import Class >>> Class.forName('net.sourceforge.jtds.jdbc.Driver') <type 'net.sourceforge.jtds.jdbc.Driver'>

但这不是吗?

$ ./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_20 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys.path.extend(['/tmp/jtds-1.2.5.jar']) >>> from java.lang import Class >>> Class.forName('net.sourceforge.jtds.jdbc.Driver') Traceback (most recent call last): File "<stdin>", line 1, in <module> at java.URLClassLoader$1.run(URLClassLoader.java:202) at java.security.AccessController.doPrivileged(Native Method) at java.URLClassLoader.findClass(URLClassLoader.java:190) at java.lang.ClassLoader.loadClass(ClassLoader.java:307) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:248) 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: net.sourceforge.jtds.jdbc.Driver >>> sys.path ['', '/home/me/pkg/jython2.5.1/Lib/site-packages/distribute-0.6.13-py2.5.egg', '/home/me/pkg/jython2.5.1/Lib', '__classpath__', '__pyclasspath__/', '/home/me/pkg/jython2.5.1/Lib/site-packages', '/home/me/pkg/jython2.5.1/Lib/site-packages/setuptools-0.6c11-py2.5.egg-info', '/tmp/jtds-1.2.5.jar'] >>> import net.sourceforge.jtds.jdbc.Driver as Driver >>> drv = Driver() >>> drv jTDS 1.2.5

和类加载器有关系吗?

推荐答案

解决方案很棘手,但一切都解释了 此处.

The solution is tricky, but everything is explained here.

更多推荐

Jython CLASSPATH、sys.path 和 JDBC 驱动程序

本文发布于:2023-11-23 21:18:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1622890.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:驱动程序   CLASSPATH   Jython   sys   JDBC

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!