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

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