I want to return primitive type after call oracle procedure, here is my mybatis interface:
public interface ProcedureMapper {
int getProcedureResult();
}
I want to execute a procedure or function then return status, I tried the config bellow:
<select id="getProcedureResult" statementType="CALLABLE" resultType="int">
BEGIN
EXECUTE IMMEDIATE 'CREATE TABLE temp_tt (id NUMBER(12) )';
#{status,mode=OUT,jdbcType=INTEGER} := 0;
EXCEPTION
WHEN OTHERS THEN
#{status,mode=OUT,jdbcType=INTEGER} := -1;
END;
</select>
doesn't work, will throw the Exception:
Caused by: org.apache.ibatis.reflection.ReflectionException: Could not set property 'status' of 'class java.lang.Class' with value 'null' Cause: org.apache.ibatis.reflection.ReflectionException: There is no setter for property named 'status' in 'class java.lang.Class'
I know I can set resultType to Java Bean with 'status' property inside, but I just want to return primitive type not java bean, any ideas?
write your procedure like this in string -
public String proc = "BEGIN\n"
+"\tEXECUTE IMMEDIATE 'CREATE TABLE temp_tt (id NUMBER(12) )';\n"
+"\tstatus := 0;\n"
+"\tEXCEPTION\n"
+"\t\tWHEN OTHERS THEN\n"
+"\tstatus := 0;\n"
+"\tEND;\n"
and execute below statement in your java code insted where you are calling that procuder in mybatis
session.getConnection().prepareCall(String.format(proc)).execute();
ANOTHER SOLUTION IS:
another solution is create a your procedure in database and save it. and call it from mybatis
<update id="getProcedureResult" statementType="CALLABLE">
{call some_procedure(
#{status, javaType=java.lang.Integer, jdbcType=INTEGER, mode=OUT})
}
</update>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.