CallableStatement interface

You can use a CallableStatement object to run SQL stored procedures. The stored procedure being called must already be stored in the database. CallableStatement does not contain the stored procedure, it only calls the stored procedure.

A stored procedure can return one or more ResultSet objects and can use IN parameters, OUT parameters, and INOUT parameters. Use Connection.prepareCall() to create new CallableStatement objects.

The following example shows how to use the CallableStatement interface.

                       // Connect to the AS/400.
     Connection c = DriverManager.getConnection("jdbc:as400://mySystem");

                       // Create the CallableStatement
                       // object. It precompiles the
                       // specified call to a stored
                       // procedure. The question marks
                       // indicate where input parameters
                       // must be set and where output
                       // parameters can be retrieved.
                       // The first two parameters are
                       // input parameters, and the third
                       // parameter is an output parameter.
     CallableStatement cs = c.prepareCall("CALL MYLIBRARY.ADD (?, ?, ?)");

                       // Set input parameters.
     cs.setInt (1, 123);
     cs.setInt (2, 234);

                       // Register the type of the output
                       // parameter.
     cs.registerOutParameter (3, Types.INTEGER);

                       // Run the stored procedure.
     cs.execute ();

                       // Get the value of the output
                       // parameter.
     int sum = cs.getInt (3);

                       // Close the CallableStatement and
                       // the Connection.
     cs.close();
     c.close();


[ Legal | AS/400 Glossary ]