After long long google search (My God! Why do we have to google for something that should be self-intuitive), I finally got my java program working and calling a store procedure from Oracle.
The code before was this:
/**
*
* @param connection
* @param xml
* @return
* @throws SQLException
*/
public String executaProcedimento (Connection connection,
String login,
String codPgm,
String xmlParams,
String urlWebAppServico)
throws SQLException{
CallableStatement
stmt = connection.prepareCall(databaseObjects.STMT_F_EXEC_PROCEDIMENTO);
//
stmt.registerOutParameter(1, OracleTypes.VARCHAR);
//
stmt.setString(2, login);
stmt.setString(3, codPgm);
stmt.setString(4, xmlParams);
stmt.setString(5, urlWebAppServico);
stmt.execute();
//System.out.println("xml:"+xml);
String result = (String)stmt.getObject(1);
stmt.close();
return result;
}
And now a proud Spring equivallent one:
/**
*
* @author Acacio Bernardo
*
*/
private class ProcedimentoTron
extends StoredProcedure {
private static final String SQL =
"oracle_package_name.f_stored_function";
public ProcedimentoTron(DataSource ds) {
setDataSource(ds);
setFunction(true);
setSql(SQL);
declareParameter(new SqlOutParameter("result", Types.VARCHAR));
declareParameter(new SqlParameter ("p_login", Types.VARCHAR));
declareParameter(new SqlParameter ("p_cod_pgm", Types.VARCHAR));
declareParameter(new SqlParameter ("p_xml_params", Types.VARCHAR));
declareParameter(new SqlParameter ("p_url_servico", Types.VARCHAR));
compile();
}
public Map executa( String login,
String codPgm,
String xmlParams,
String urlWebAppServico) {
//
Map inputs = new HashMap();
inputs.put("p_login", login);
inputs.put("p_cod_pgm", codPgm);
inputs.put("p_xml_params", xmlParams);
inputs.put("p_url_servico", urlWebAppServico);
return execute(inputs);
}
}
/**
*
* @param connection
* @param xml
* @return
* @throws SQLException
*/
public String executaProcedimento (DataSource ds,
String login,
String codPgm,
String xmlParams,
String urlWebAppServico)
throws SQLException{
ProcedimentoTron proc =
new ProcedimentoTron(ds);
Map results = proc.executa(login, codPgm, xmlParams, urlWebAppServico);
return (String) results.get("result").toString();
}
The Oracle page where I found the information has an example, but it wasn't working because the order of the parameters was Wrong.
Is seems that first you must define the out parameter, and then the input parameters.