Spring Mybatis – sending array as input parameter to procedure call in mapper.xml

mybatisspring

I'm using the following code for passing java array to stored procedure

<select id="abcd" parameterType="java.util.Map" statementType="CALLABLE">
    {call PKG_xyz.PR_cbcd(
        #{p_array,jdbcType=ARRAY,typeHandler=org.apache.ibatis.type.ArrayTypeHandler,mode=IN},
        #{p_ids,jdbcType=INTEGER,mode=IN},
        #{p_comments,jdbcType=VARCHAR,mode=IN},
        #{p_return_code,jdbcType=INTEGER,mode=OUT},
        #{p_msg_out,jdbcType=VARCHAR,mode=OUT}   
    )}
</select>

here, p_array is my java array. But i'm getting the following error –>
"Error setting null for parameter #1 with JdbcType ARRAY . Try setting a different JdbcType for this parameter or a different jdbcTypeForNull configuration property. Cause: java.sql.SQLException: Invalid column type: sqlType=2003"

Could somebody please help….

Thanks in advance…

Best Answer

Try to write your custom TypeHandler like

public class ArrayTypeHandler implements TypeHandler<YourArrayObject[]>{
}

Override this method below to set oracle.sql.ARRAY to PreparedStatement:-

public void setParameter(PreparedStatement ps, int i,
            YourArrayObject[] parameter, JdbcType jdbcType) throws SQLException {}

This url might help you do the same:- How to Pass Java List of Objects to Oracle Stored Procedure Using MyBatis?

Similarly, override getResult() method to get OUT array paramter

Related Topic