I have a function that returns a boolean value in pl/sql. I have tried to get directly that boolean value without success, so now I'm trying to convert it to string (I do not want to modify the database):
<parameterMap id="publicObject" type="map">
<parameter javaType="java.lang.Object" jdbcType="VARCHAR" mode="OUT" property="result" />
<parameter javaType="java.lang.String" jdbcType="VARCHAR" mode="IN" property="id" />
</parameterMap>
<select id="isPublicObject" parameterMap="publicObject" statementType="CALLABLE">
<![CDATA[
{
declare
v_bool BOOLEAN := TRUE;
begin
v_bool := PACKNAME.STF$IS_PUBLIC_OBJECT(#{id});
#{result} := CASE WHEN v_bool THEN 'TRUE' ELSE 'FALSE' END;
end;
}
]]>
</select>
Then I get this exception: "Error querying database. Cause: org.apache.ibatis.type.TypeException: Error setting null for parameter #2 with JdbcType OTHER. Try setting a different JdbcType for this parameter or a different jdbcTypeForNull configuration property. Cause: java.sql.SQLException: Invalid column type: 1111 ####
This code works correctly in the database:
declare
v_bool BOOLEAN := TRUE;
v_str VARCHAR2(5);
begin
v_bool := PACKNAME.STF$IS_PUBLIC_OBJECT('000000');
v_str := CASE WHEN v_bool THEN 'TRUE' ELSE 'FALSE' END;
dbms_output.put_line('result:');
dbms_output.put_line(v_str);
end;
MyBatis is an SQL Mapper tool which greatly simplifies the database programing when compared to using JDBC directly. Step1: Create a Maven project and configure MyBatis dependencies. Step#3: Create MyBatis configuration files. Step#4: Create an interface UserMapper.
The resultMap element is the most important and powerful element in MyBatis. It's what allows you to do away with 90% of the code that JDBC requires to retrieve data from ResultSet s, and in some cases allows you to do things that JDBC does not even support.
to call a stored procedure usgin mybatis/ibatis 3 you will have to follow some tips: must set the statement type to callable. must use the jdbc standard escape sequence for stored procedures: { call xxx (parm1, parm2) } must set the mode of all parameters ( in, out, inout )
I wrote parameterType
& Map
example. It works on my test data.
XML:
<update id="isPublicObject" parameterType="map" statementType="CALLABLE">
declare
v_bool BOOLEAN := TRUE;
begin
v_bool := PACKNAME.STF$IS_PUBLIC_OBJECT(#{id});
#{result,jdbcType=VARCHAR,mode=OUT} := CASE WHEN v_bool THEN 'TRUE' ELSE 'FALSE' END;
end;
</update>
Mapper:
public interface PLSQLMapper {
public void isPublicObject(Map<String, Object> parameterMap);
}
Main:
PLSQLMapper mapper = session.getMapper(PLSQLMapper.class);
Map<String, Object> parameterMap = new HashMap<String, Object>();
parameterMap.put("id", 1);
mapper.isPublicObject(parameterMap);
System.out.println("result: " + parameterMap.get("result"));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With