2

Could you please enlighten me on how to connect to an Oracle instance using Python/Jython ?

After installing fully Jython, the Oracle website (http://www.oracle.com/technetwork/articles/dsl/mastering-oracle-python-providers-1395759.html) suggests to : All you need to provide is to make sure ojdbc6.jar is in the CLASSPATH or JYTHONPATH so that the connection driver could be resolved.

I read that when using the -jar option ignores the CLASSPATH environment variable. So I did like :

java -classpath /usr/lib/oracle/12.1/client64/lib/ojdbc6.jar  -jar jython.jar

from java.sql import DriverManager
db_connection = DriverManager.getConnection("jdbc:oracle:thin:@xxxxx:1521/P1FNTPE", "xxx", "xxx")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
    at java.sql.DriverManager.getConnection(DriverManager.java:596)
    at java.sql.DriverManager.getConnection(DriverManager.java:215)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)

java.sql.SQLException: java.sql.SQLException: No suitable driver found for jdbc:oracle:thin:@xxxxx:1521/P1FNTPE

Could you please help/advise me on how to resolve this issue ?

14
  • 1
    See my answer here about setting up Jython for JDBC on *nix. You would need to have /usr/lib/oracle/12.1/client64/lib/ojdbc6.jar in your CLASSPATH (instead of the JARs I mention for UCanAccess). Note that it uses from com.ziclix.python.sql import zxJDBC. Note also that invoking Jython is done with a jython command, not java -jar jython.jar (at least that's how it worked for me). Commented Jan 18, 2015 at 15:38
  • Thanks Gord. I would need a bit of extra help if possible. Commented Jan 18, 2015 at 16:28
  • UCanAccess, i guess is not needed because is not about the MS Access DB Commented Jan 18, 2015 at 16:30
  • could you please explain how to call jython and update CLASSPATH ? Commented Jan 18, 2015 at 16:30
  • 1
    Try export CLASSPATH=/usr/lib/oracle/12.1/client64/lib/ojdbc6.jar Commented Jan 18, 2015 at 20:09

1 Answer 1

1

As mentioned in the question, the full path to the JAR file for the JDBC driver must be present in either the CLASSPATH or the JYTHONPATH environment variable so the Jython script can find it. These variables can be modified in several ways depending on the environment (shell) being used, as described in the Jata tutorial here:

PATH and CLASSPATH

In this particular case, simply adding the line

export CLASSPATH=/usr/lib/oracle/12.1/client64/lib/ojdbc6.jar

to one of the startup files (e.g., ~/.bash_profile, ~/.profile, ~/.bashrc, ...) and then logging back in (or running source on the file) was the solution.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.