Search code examples
oracle-databasemappingblobibatis

How to Select a BLOB column from database using iBatis


One of a table's column is of BLOB datatype (Oracle 10g). We have a simple select query executed via iBatis to select the BLOB column and display it using Struts2 & JSP.

The result tag in the iBatis xml file had the jdbctype as java.sql.Blob

<result property="uploadContent" column="uploadcontent" jdbctype="Blob"/>   

Should we be mentioning any typeHandler class for Blob column ? Currently we are getting an error stating column type mismatch.

Note: This column is selected and mapped into a java bean who has an attribute of type java.sql.Blob


Solution

  • I think you cannot use native jdbctype for LOB types in Oracle with iBatis. The solution is to create custom typeHandler to handle LOB and then map it like -

    <result property="aClassStringProperty" column="aClobColumn" typeHandler="com.path.to.my.ClobTypeHandler"/>
    

    More information on typeHandlerCallback here.