1
您好我正在嘗試使用Spring JDBC執行存儲過程。 這是SP類使用Spring JDBC的Oracle存儲過程
class IncrementExtraBalanceStoredProcedure extends StoredProcedure {
/**
* @param jdbcTemplate
* @param procedureName
*/
public IncrementExtraBalanceStoredProcedure(JdbcTemplate jdbcTemplate, String procedureName) {
super(jdbcTemplate, procedureName);
declareParameter(new SqlOutParameter(O_RETURN_CODE, Types.INTEGER));
declareParameter(new SqlParameter(P_NUMEC, Types.INTEGER));
declareParameter(new SqlParameter(P_GBYTES, Types.INTEGER));
compile();
}
/**
* @param inputBean
* @return resultObjects
*/
public Map<String, Object> execute(RateLimitLogBean inputBean) {
Map<String,Object> sqlMap = new HashMap<String,Object>();
sqlMap.put(P_NUMEC, inputBean.getNumec());
sqlMap.put(P_GBYTES, inputBean.getGb());
return super.execute(sqlMap);
}
}
我從這個方法調用這個類。
public int incrementExtraBalance(RateLimitLogBean inputBean) {
IncrementExtraBalanceStoredProcedure procedure = new IncrementExtraBalanceStoredProcedure(this.jdbcTemplate, "RATELIMIT_OWN.increment_extra_balance");
Map<String, Object> resultMap = procedure.execute(inputBean);
if (!StringUtils.isEmpty(resultMap)) {
return ((Integer) resultMap.get(O_RETURN_CODE)).intValue();
}
return -1;
}
但是我得到空值作爲O_RETURN_CODE。它應該返回0 從蟾蜍這個函數的執行 - Oracle數據庫
變種z個
EXEC RATELIMIT_OWN.unlimit_contract(0123:Z)
打印ž
我得到0作爲蟾蜍輸出。
爲什麼我將null值作爲Java代碼返回(無sql異常)。 代碼有什麼問題嗎?
本地調用的參數,返回正確的輸出
public void unlimitContract(RateLimitLogBean inputBean, boolean load) throws SQLException {
String sql = "{call RATELIMIT_OWN.unlimit_contract (?,?)}";
CallableStatement callableStatement = this.dataSource.getConnection().prepareCall(sql);
callableStatement.setInt(1, 0123);
callableStatement.registerOutParameter(2, java.sql.Types.INTEGER);
callableStatement.executeUpdate();
int resultCode = callableStatement.getInt(2);
}
SQL SP
CREATE OR REPLACE PROCEDURE RATELIMIT_OWN.increment_extra_balance (p_numec IN NUMBER,
p_gbytes IN NUMBER,
o_return_code OUT NUMBER)
AS
message logs.errormsg%TYPE;
BEGIN
update balance set extrabalance=extrabalance+(p_gbytes*1073741824),limited=0 WHERE numec = p_numec;
IF SQL%ROWCOUNT = 0
THEN
o_return_code:=1;
ELSE
o_return_code:=0;
message := 'Cops added ' || p_gbytes || ' gb extra volume';
INSERT INTO logs (logid, eventid, origin, numec, VALUE, errormsg) VALUES (seq_log.NEXTVAL, 'NEXTRAROV', 'increment_extra_balance', p_numec, p_gbytes, message);
END IF;
commit;
EXCEPTION
WHEN OTHERS
THEN
o_return_code := SQLCODE;
ROLLBACK;
END;
/
真的很感謝。這很有幫助。這是一個愚蠢的錯誤,花了一天對我來說 – Reddy
你可以請看看這一個也是一個地獄http://stackoverflow.com/questions/12388626/executing-oracle-functions-using-spring-jdbc – Reddy