Retrieving a CLOB in iBatis

Retrieving a CLOB in iBatis

When I was but a youngling and the Force was yet to fully develop within me, I had issues calling stored procedures which returned a CLOB.

I’m pleased that those days are behind me (somewhat) and I now want to share my learnings with you.

It’s really very easy and doesn’t even require that you write your own custom type handler.

Just add the following to your SqlMapConfig

<typeHandler javaType="java.sql.Clob"
callback="com.ibatis.sqlmap.engine.type.ClobTypeHandlerCallback"/>

What this does is force Ibatis to use the specified handler when dealing with the java type specified. So in this case, we’re telling Ibatis to use the ClobTypeHandlerCallback when dealing with objects of type java.sql.Clob.

Just one other step is required. Ensure that you have the correct type mapping in your parameter map.

<parameter property="r_clob" jdbcType="CLOB" javaType="java.sql.Clob" mode="OUT"/>

Remember to cast your return value when getting it back.

String c = (String) params.get("r_clob");

And viola! That’s it. Go ahead and test it out.

Enjoy.

Leave a Reply

Your email address will not be published. Required fields are marked *