我试图从我的ADF应用程序调用SQL过程。
我的AppModule中有以下代码:
public void callProcedureSimulateFromDB(String idCategoria) {
CallableStatement cs = null;
System.out.println("categoria-> " + idCategoria);
try {
cs = getDBTransaction().createCallableStatement("begin ? := SPSIMULATE(?); end;", 0);
cs.setString(2, idCategoria);
cs.execute();
} catch (SQLException e) {
throw new JboException(e);
} finally {
if (cs != null) {
try {
cs.close();
}catch (SQLException e) {}
}
}
}
这是在我的支持bean中,我调用了上一个方法:
public String simulate() {
String categoria = catIdId.getValue().toString();
if (categoria != null && !categoria.isEmpty()) {
FacesContext facesContext = FacesContext.getCurrentInstance();
Application app = facesContext.getApplication();
ExpressionFactory elFactory = app.getExpressionFactory();
ELContext elContext = facesContext.getELContext();
ValueExpression valueExp = elFactory.createValueExpression(elContext, "#{bindings}", Object.class);
oracle.binding.BindingContainer binding = (oracle.binding.BindingContainer)valueExp.getValue(elContext);
OperationBinding operationBinding = binding.getOperationBinding("callProcedureSimulateFromDB");
// Set the Input parameters to the operation bindings as below
operationBinding.getParamsMap().put("idCategoria", categoria);
// Invoke the Application module method
operationBinding.execute();
// Get the result from operation bindings
//Object obj = operationBinding.getResult();
//System.out.println("obj ----> " + obj);
}
//ADFContext.object.applicationModule.myAMMethod() ;
//chamar funçao da DB
p55.hide();
return null;
}
我收到以下错误:
我做错了什么?我尝试更改可调用语句和cs.setString()
中的数字。但问题仍然存在。
编辑: 在对代码进行一些更改后,我测试了AppModule并得到以下错误:
(oracle.jbo.JboException) JBO-29000: Unexpected exception caught: java.sql.SQLException, msg=ORA-06550: line 1, column 7:
PLS-00103: Encountered the symbol "=" when expecting one of the following:
( begin case declare exit for goto if loop mod null pragma
raise return select update while with <an identifier>
<a double-quoted delimited-identifier> <a bind variable> <<
continue close current delete fetch lock insert open rollback
savepoint set sql execute commit forall merge pipe purge
The symbol "<an identifier>" was substituted for "=" to continue.
答案 0 :(得分:0)
如果SPSIMULATE是存储过程(而不是存储的函数),您可以尝试更改此行:
cs = getDBTransaction().createCallableStatement("begin ? := SPSIMULATE(?); end;", 0);
要
cs = getDBTransaction().createCallableStatement("{call SPSIMULATE(?)}", 0);
确保从BC Tester测试您的程序,然后从支持bean进行测试。较小的步骤总是更快。