O'Reilly logo

Oracle and PL/SQL Recipes: A Problem-Solution Approach by Matt Arena, Josh Juneau

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

16-4. Accessing PL/SQL from Jython

Problem

You are working with a Jython program and want to call some PL/SQL stored procedures or functions from it.

Solution #1

Use Jython's zxJDBC API to obtain a connection to the Oracle Database, and then call the PL/SQL stored procedure passing parameters as required.  The following code is an example of a Jython script that performs these tasks:

from __future__ import with_statement from com.ziclix.python.sql import zxJDBC # Set up connection variables jdbc_url = "jdbc:oracle:thin:@host:1521:dbname" username = "user" password = "password" driver = "oracle.jdbc.driver.OracleDriver" # obtain a connection using the with-statment with zxJDBC.connect(jdbc_url, username, password, driver) as conn:     with ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required