16-1. Accessing a PL/SQL Stored Procedure via JDBC

Problem

You are writing a Java application that uses JDBC to access data, but you also want to call some PL/SQL stored procedures from within your Java application.

Solution

Use the JDBC API to connect to the database, and then execute prepareCall(), passing a string to it that consists of a PL/SQL code block that calls the stored procedure. For example, consider a stand-alone Java class that contains a method named increaseWage(). This method uses JDBC to obtain a database connection, create a CallableStatement, and then invoke the PL/SQL stored procedure that passes in the required variables.

import java.sql.*; import oracle.jdbc.*; public class EmployeeFacade {  public void increaseWage() ...

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.