无法使用Spring JDBC调用存储过程

时间:2014-06-24 06:50:54

标签: oracle stored-procedures plsql spring-jdbc complextype

我们无法使用Spring JDBC调用存储过程。以下是代码段。

Procedure Signature

    PROCEDURE get_cash_details (
        p_org_id      IN      VARCHAR2,
        p_receipt_number  IN      VARCHAR2,
        p_result_type     IN      VARCHAR2,
        x_cash_detail     OUT     CASH_DETAIL_REC,
        x_error_msg   OUT     VARCHAR2
    );


The CASH_DETAIL_REC is of type STRUT returning a record type and 2 Arrays

Java代码:

public void callStoredProcedure(String receiptNumber, String orgId, String type) {
    CashDetailsProcedure procedure = new CashDetailsProcedure(jdbcTemplate);
    procedure.execute();
}

public class CashDetailsProcedure extends StoredProcedure {

    @Autowired
    JdbcTemplate jdbcTemplate;

    public CashDetailsProcedure(JdbcTemplate jdbcTemplate) {
        super(jdbcTemplate, "BPEL_LLPOCWRAPPER.XX_AR_CASHRCPT_RCV_PKG$GET_CA ");


        declareParameter(new SqlParameter("P_ORG_ID", OracleTypes.VARCHAR));
            declareParameter(new SqlParameter("P_RECEIPT_NUMBER", Types.VARCHAR));
        declareParameter(new SqlParameter("P_RESULT_TYPE", Types.VARCHAR));

        declareParameter(new SqlOutParameter("X_CASH_DETAIL", OracleTypes.STRUCT, "XX_AR_CASHRCPT_RX3372075X1X4", new ReceiptHandler()));
            declareParameter(new SqlOutParameter("X_ERROR_MSG", OracleTypes.VARCHAR));

            compile();   
    }

        public Map<String, Object> execute() {

            Map<String, Object> inParams = new HashMap<String, Object>();
            inParams.put("P_ORG_ID", "204");
        inParams.put("P_RECEIPT_NUMBER", "89067");
        inParams.put("P_RESULT_TYPE", "Summary");
            Map output = execute(inParams);
            return output;
        }

}

错误讯息:

CallableStatementCallback; uncategorized SQLException for SQL 
[{call BPEL_LLPOCWRAPPER.XX_AR_CASHRCPT_RCV_PKG$GET_CA (?, ?, ?, ?, ?)}]; 
SQL state [null]; error code [17090]; operation not allowed: Ordinal binding
and Named binding cannot be combined!; nested exception is java.sql.SQLException:
operation not allowed: Ordinal binding and Named binding cannot be combined!

1 个答案:

答案 0 :(得分:0)

您可以将简单查询定义为

String query = "Select * from yourStoredProcedureName(?,?,?);"

并且在使用jdbcTemplate调用时,您可以使用两个方法映射器或不使用映射器。 1 GT; jdbcTemplate.queryForObject(query,yourMapper, param1, param2, param3); 2 - ;

List<Map<String, Object>> rows = jdbcTemplate.queryForList(query, param1, param2, param3);
            for (Map<String, Object> row : rows) {
                System.out.println(row.get("firstName"));
}

第二种方法从那里给出行,你可以得到每个结果列的结果。