1

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:

enter image description here

(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 
Community
  • 1
  • 1
mike rodent
  • 10,479
  • 10
  • 80
  • 104
  • The jdbc url is correct, what's the java version working behind? – jamadei Oct 30 '15 at 14:59
  • thanks. Pls forgive me if I'm not totally clear how to answer your question: the OS JAVA_HOME Env Var points to jdk1.7.0_79. The Windows PATH Env Var includes jdk1.7.0_79\jre\bin, and as for Eclipse, I'm a bit stumped how it goes looking for its JRE when running a Jython project, but under Preferences --> Java --> Installed JREs, again it is pointing to jdk1.7.0_79. Are you suggesting that I am actually **obliged** to move to Java 8??? – mike rodent Oct 30 '15 at 15:12
  • In your batch file, try setting the CLASSPATH to include the individual JAR files. I just tried [this](http://pastebin.com/GmwFxtV8) and it worked for me. – Gord Thompson Oct 30 '15 at 15:41
  • @GordThompson thanks. I had already tried that and many other permutations, but in fact I posted another question today to do with loading jars in Jython 2.7.0FR ("final release"): http://stackoverflow.com/questions/33434083/jython-2-7-0-final-release-on-windows-difficulty-including-jars. I notice that in your snippet you are using Jython 2.5.3. Have you tried using Ucanaccess with 2.7.0FR? PS the fact that I get '# appear to have imported...' after using "dynamic loading" (sys.path.append...) seems to show that I *have* loaded these jars. – mike rodent Oct 30 '15 at 18:09
  • No, l just wanted to know if it was java6. But it isn't. – jamadei Oct 30 '15 at 20:40

1 Answers1

2

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.)

Gord Thompson
  • 98,607
  • 26
  • 164
  • 342
  • Thanks... found the problem: I had not realised that the ucanaccess jar goes in the directory, whereas the other 4 jars go in a subdirectory called "lib". Have also found, partly due to your answer here, the answer to the general probs I had with loading jars with 2.7.0FR: forward slashes and paths without spaces... (appears to be a change relative to 2.7b1). – mike rodent Oct 31 '15 at 14:30