16-4. Accessing PL/SQL from Jython


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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.