Oracle 5.0 Reference Manual page 2110

Table of Contents

Advertisement

that when using CallableStatement,
NULL.
The following example shows a stored procedure that returns the value of
by 1, and the string passed in using
Example 20.3. Connector/J: Calling Stored Procedures
CREATE PROCEDURE demoSp(IN inputParam VARCHAR(255), \
BEGIN
DECLARE z INT;
SET z = inOutParam + 1;
SET inOutParam = z;
SELECT inputParam;
SELECT CONCAT('zyxw', inputParam);
END
To use the
procedure with Connector/J, follow these steps:
demoSp
1. Prepare the callable statement by using Connection.prepareCall().
Notice that you have to use JDBC escape syntax, and that the parentheses surrounding the
parameter placeholders are not optional:
Example 20.4. Connector/J: Using
import java.sql.CallableStatement;
...
//
// Prepare a call to the stored procedure 'demoSp'
// with two parameters
//
// Notice the use of JDBC-escape syntax ({call ...})
//
CallableStatement cStmt = conn.prepareCall("{call demoSp(?, ?)}");
cStmt.setString(1, "abcdefg");
2. Register the output parameters (if any exist)
To retrieve the values of output parameters (parameters specified as
created the stored procedure), JDBC requires that they be specified before statement execution
using the various
registerOutputParameter()
interface:
Example 20.5. Connector/J: Registering output parameters
import java.sql.Types;
...
//
// Connector/J supports both named and indexed
// output parameters. You can register output
JDBC Concepts
inputParam
INOUT inOutParam INT)
Connection.prepareCall()
Note
Connection.prepareCall()
the metadata retrieval that the driver performs to support output
parameters. For performance reasons, minimize unnecessary calls to
Connection.prepareCall()
instances in your code.
2090
ResultSetMetaData
as a ResultSet:
is an expensive method, due to
by reusing
CallableStatement
methods in the
CallableStatement
may return
incremented
inOutParam
or
when you
OUT
INOUT

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents