Neoview Guide to Stored Procedures in Java (R2.3, R2.4)

SQLINTEGER indicator;
rc = SQLBindParameter(s, 2, SQL_PARAM_OUTPUT, SQL_C_SBIGINT, SQL_BIGINT,
0, 0, &num_orders, 0, &indicator);
/* Execute the CALL */
rc = SQLExecute(s);
/* Process all returned result sets. The outer while loop repeats */
/* until there are no more result sets. */
while ((rc = SQLMoreResults(s)) != SQL_NO_DATA)
{
/* The inner while loop processes each row of the current result set */
while (SQL_SUCCEEDED(rc = SQLFetch(hStmt)))
{
/* Process the row */
}
}
Calling SPJs From a JDBC Client Application
You can execute a CALL statement in a JDBC client application by using the JDBC
CallableStatement interface. The Neoview JDBC Type 4 driver requires that you put the
CALL statement in an escape clause:
{call procedure-name ([parameter[{, parameter}...]])}
Set input values for IN and INOUT parameters by using the settype() methods of the
CallableStatement interface.
Retrieve output values from OUT and INOUT parameters by using the gettype() methods of
the CallableStatement interface.
If the parameter mode is OUT or INOUT, you must register the parameter as an output parameter
by using the registerOutParameter() method of the CallableStatement interface before
executing the CALL statement.
In this example, a CALL statement is executed from a JDBC client application:
CallableStatement stmt =
con.prepareCall("{call adjustsalary(?,?,?)}");
stmt.setBigDecimal(1,202); // x = 202
stmt.setDouble(2,5.5); // y = 5.5
stmt.registerOutParameter(3, java.sql.Types.NUMERIC);
stmt.execute();
BigDecimal z = stmt.getBigDecimal(3); // Retrieve the value of the
// OUT parameter
For more information about the JDBC Type 4 driver and mappings of SQL to JDBC data types,
see the Neoview JDBC Type 4 Driver Programmer’s Reference.
Returning Result Sets in a JDBC Client Application
This example shows serial result set processing in a JDBC client application where the result sets
are processed in order and one at a time after the CALL statement executes. The
java.sql.Statement.getMoreResults() method closes the current result set and moves
processing to the next available result set.
// Prepare a CALL statement
java.sql.CallableStatement s = myConnection.prepareCall (
"{call sales.ordersummary('01-01-2001', ?)}" );
// Register an output parameter
s.registerOutParameter(1, java.sql.Types.BIGINT);
Calling SPJs From a JDBC Client Application 69