Neoview Guide to Stored Procedures in Java (R2.5)

NOTE: The Neoview ODBC API does not currently support interleaved result set processing,
where more than one returned result set can be open at a time.
/* Allocate a statement handle */
SQLHSTMT s;
RETCODE rc = SQLAllocHandle(SQL_HANDLE_STMT, myConnection, &s);
/* Prepare a CALL */
char *stmtText = "{call sales.ordersummary('01-01-2001', ?)}";
rc = SQLPrepare(s, (SQLCHAR *) stmtText, strlen(stmtText));
/* Bind the output parameter */
_int64 num_orders = 0;
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.
Calling SPJs From a JDBC Client Application 57