ibtatis调用有输出参数的mysql存储过程的时候,居然要使用insert写法,汗!
procedure==========================================================
CREATE PROCEDURE SYS_SEQ_NEXTVAL_SP(in p_name varchar(10),out p_val int)
BEGIN
declare c_val int default 0;
select c_cur_val into c_val from SYS_SEQUENCE where c_name=p_name;
if c_val =0 then
set p_val=1;
insert into SYS_SEQUENCE values (p_name,1);
commit;
else
set p_val=c_val+1;
UPDATE SYS_SEQUENCE
SET C_CUR_VAL= C_CUR_VAL+1
WHERE C_NAME=p_name;
COMMIT;
end if;
END;
configuration file ================================================
javaType="java.lang.String" mode="IN" />
javaType="java.lang.Integer" mode="OUT" />
{CALL SYS_SEQ_NEXTVAL_SP (?,?)}
java file========================================================
public int doFindNextval(String prefix) throws Exception{
Map t_swapMap = new HashMap();
Integer t_seq = null;
t_swapMap.put("p_name", prefix);
t_swapMap.put("p_val", t_seq);
getIbatis().insert(S_GET_NEXTVAL, t_swapMap);
int result = ((Integer)t_swapMap.get("p_val")).intValue();
if( result <= 0 ){
throw new RuntimeException("get sequence failed.");
}
return result;
}