在从命令行调用的Jython脚本中使用UCanAccess [英] Using UCanAccess in a Jython script invoked from the command line

查看:288
本文介绍了在从命令行调用的Jython脚本中使用UCanAccess的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

操作系统:Windows7,Jython2.7.0FR(最终版本)



尝试通过Jython使用Gord Thompson的解决方案:



(这个输出是复制到Eclipse中的:



任何人都知道为什么我会得到没有合适的司机...? NB我尝试了各种排列与反斜杠,而不是前进的getConnection ...无效。



顺便说一下,如果这是相关的,这是一个提取从我使用的.bat文件运行的东西:

  cd%SOFTWARE_PROJECTS%\workspace\Jython暂时\src\jython_scratchpad_root

REM这可能是不相关的,似乎不适用于Jython2.7.0FR。正在通过sys.path.append加载jars,显然
设置CLASSPATH = ;.%SYSADMIN%\resources\java jar文件/ *

D:\apps \ jython2.7.0\bin\jython loading_test.py


解决方案

看起来 sys.path PATH 环境变量c> CLASSPATH 环境变量。以下两个方法已经过测试,并使用Jython 2.7.0从Windows命令行运行名为jyTest.py的脚本



方法1 :在启动Jython之前从批处理文件(或shell脚本)设置CLASSPATH

  SET CLASSPATH = C:/Users/Public/Downloads/UCanAccess/ucanaccess-3.0.2.jar; C:/Users/Public/Downloads/UCanAccess/lib/commons-lang-2.6。 jar; C:/Users/Public/Downloads/UCanAccess/lib/commons-logging-1.1.1.jar; C:/Users/Public/Downloads/UCanAccess/lib/hsqldb.jar; C:/ Users / Public / Downloads /UCanAccess/lib/jackcess-2.1.2.jar ;. 
c:\ jython2.7.0\bin\jython jyTest.py

Linux等。 export CLASSPATH ... 和冒号分隔符,而不是分号。)



方法2:使用 -J-cp 在调用Jython时设置CLASSPATH

  c:\ jython2.7.0\bin\jython -J-cp C:/Users/Public/Downloads/UCanAccess/ucanaccess-3.0.2。 jar; C:/Users/Public/Downloads/UCanAccess/lib/commons-lang-2.6.jar; C:/Users/Public/Downloads/UCanAccess/lib/commons-logging-1.1.1.jar; C:/ Users /Public/Downloads/UCanAccess/lib/hsqldb.jar;C:/Users/Public/Downloads/UCanAccess/lib/jackcess-2.1.2.jar ;. jyTest.py 

(再次,Linux和朋友需要 / code>条目以冒号分隔,而不是分号。)


OS: Windows7, Jython2.7.0FR ("Final Release")

Trying to use Gord Thompson's solution with Jython: Manipulating an Access database from Java without ODBC

I can get the Ucanaccess module to work in Eclipse, but not when I try running from the CLI.

# -*- coding: utf-8 -*-
import java, sys
jars_dir = 'D:\\sysadmin\\Resources\\Java jar files\\'
sys.path.append( jars_dir + 'commons-lang-2.6.jar' )
sys.path.append( jars_dir + 'commons-logging-1.2.jar' )
sys.path.append( jars_dir + 'hsqldb.jar' )
sys.path.append( jars_dir + 'jackcess-2.1.2.jar' )
sys.path.append( jars_dir + 'ucanaccess-3.0.2.jar' )
import net.ucanaccess.jdbc.UcanaccessDriver
import net.ucanaccess
print( '# appear to have imported UcanaccessDriver' )
conn = java.sql.DriverManager.getConnection( 'jdbc:ucanaccess://D:/TESTING.mdb' )
print( '# conn OK...') 

This prints out "# conn OK" when I run this in Eclipse. When I run it from the CLI it prints out "# appear to have imported..." but then an error is thrown:

(NB this output was copied to Eclipse: it is indeed a CLI run)

Anyone got any idea why I might be getting "No suitable driver..."? NB I tried various permutations with backward slashes instead of forward ones in getConnection... to no avail.

By the way, in case this is relevant, this is an extract from the .bat file I'm using to run the thing:

cd "%SOFTWARE_PROJECTS%\workspace\Jython scratchpad\src\jython_scratchpad_root"

REM this is probably irrelevant and doesn't seem to work with Jython2.7.0FR.  The jars are being loaded by sys.path.append, obviously
set CLASSPATH=.;"%SYSADMIN%\resources\java jar files/*"

D:\apps\jython2.7.0\bin\jython loading_test.py 

解决方案

It appears that sys.path has more to do with the PATH environment variable than the CLASSPATH environment variable. The following two methods have been tested and do work with Jython 2.7.0 to run a script called "jyTest.py" from the Windows command line

Method 1: Set the CLASSPATH from a batch file (or shell script) before launching Jython

SET CLASSPATH=C:/Users/Public/Downloads/UCanAccess/ucanaccess-3.0.2.jar;C:/Users/Public/Downloads/UCanAccess/lib/commons-lang-2.6.jar;C:/Users/Public/Downloads/UCanAccess/lib/commons-logging-1.1.1.jar;C:/Users/Public/Downloads/UCanAccess/lib/hsqldb.jar;C:/Users/Public/Downloads/UCanAccess/lib/jackcess-2.1.2.jar;.  
c:\jython2.7.0\bin\jython jyTest.py

(For Linux et. al. that would be export CLASSPATH ..., and colon separators instead of semicolons.)

Method 2: Use -J-cp to set the CLASSPATH when invoking Jython

c:\jython2.7.0\bin\jython -J-cp C:/Users/Public/Downloads/UCanAccess/ucanaccess-3.0.2.jar;C:/Users/Public/Downloads/UCanAccess/lib/commons-lang-2.6.jar;C:/Users/Public/Downloads/UCanAccess/lib/commons-logging-1.1.1.jar;C:/Users/Public/Downloads/UCanAccess/lib/hsqldb.jar;C:/Users/Public/Downloads/UCanAccess/lib/jackcess-2.1.2.jar;. jyTest.py

(Again, Linux and friends would need the -cp entries to be separated by colons instead of semicolons.)

这篇关于在从命令行调用的Jython脚本中使用UCanAccess的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆