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
I found somebody who deal with this here.
For a CLOB :
For a BLOB :
I am still looking for it to work with C# !
I think you cannot use native
jdbctype
forLOB
types in Oracle withiBatis
. The solution is to create customtypeHandler
to handleLOB
and then map it like -More information on
typeHandlerCallback
here.I dindn't have problems using INSERTs, my problems where when I did SELECT of the blob type. I am using Oracle 9i and this is how I've done:
Add the Oracle JDBC driver to your project, you will need
mybatis
dependencies too. If you are using Maven:Add the custom BaseTypeHandler for reading byte[] from Oracle BLOB class:
Add the type handlers package to mybatis configuration. As you can see, I am using spring-mybatis:
And then, you can read byte[] from Oracle BLOBs from Mybatis:
I hope this will help. This is an adaptation of this excellent answer: This is an adaptation of this excellent answer: https://stackoverflow.com/a/27522590/2692914.
It is not neccesary to create a typeHandler. For Oracle, the jdbctype is BLOB
Assumming "bytes" as byte [].
The important thing: in the select sql, you must set the jdbcType in this way:
I noticed that this jdbctype for Postgresql is different. You must set: