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

Get Oracle and PL/SQL Recipes: A Problem-Solution Approach now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.