Previous Topic

Next Topic

Calling Stored Procedures from JDBC

The JDBC call escape sequence is the same as in ODBC:

{ call proc_name [ ( parameter [ , … ] ) ] }

Embed the escape sequence in a JDBC CallableStatement.prepareCall() method invocation. The following example shows the JDBC code parallel to the ODBC code excerpt shown in the previous example.

Invoking a Stored Procedure from a JDBC Application


try {
     CallableStatement statement;
     int Part_num = 318;
    
// Associate the statement with the procedure call
     // (conn is a previously-instantiated connection object)
     statement = conn.prepareCall("{call order_parts(?)}");
    
// Bind the parameter.
     statement.setInt(1, Part_num);
    
// Execute the statement.
     statement.execute();
}