简体   繁体   中英

How to use OJDBC as an external jar to a Jython script when called from the command line

I have a Jython script which via the java.sql packages accesses an Oracle database. For this to work it needs the ojdbc6.jar .

When I run the script from the command line via

java -jar lib/jython.jar my-script.jy

the script starts up properly, but on the first SQL call it errors out with " java.sql.SQLException: No suitable driver found " indicating that it cannot find ojdbc6.jar .

How can I tell with a terminal command like the one above where the script can find the ojdbc6.jar ?

PS:

Separately I set up the script inside an Eclipse Java project where I have added ojdbc6.jar (and of course jython.jar ) as libraries. When I use a little wrapper Java class which instantiates a PythonInterpreter and calls the script via PythonInterpreter.execfile everything works fine: The script executes the SQL statements and gets the data from the Oracle database as expected. So clearly the Java project tells the script correctly where ojdbc6.jar is. But how can I do the same on the command line?

i use this jython code for MS SQL Connection

   import sys 
   sys.path.append("C:\\Libs\\MyJavaPackage.jar")
   sys.path.append("C:\\Libs\\mssql-jdbc.jar") 
   import MyJavaPackage.MySQLClass
   import com.microsoft.sqlserver.jdbc.SQLServerDriver // use same import for oracle driver
   temp = MyJavaPackage.MySQLClass() // new java class instance
   temp.mySQLfunc() // function that use SQL Driver

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM