Here is an example of how to use the Custom Type Handler (CTH) feature of iBatis with large objects (LOB) such as BLOB's (Binary) and CLOB's (Character). As of release 2.0.9 the iBatis framework has the default CLOB and BLOB type handlers included. The example below was done for Oracle but should work for any database with a well written JDBC driver. Make sure that you do not use the thin driver supplied from Oracle. You need to use the latest ojbc14.jar.
The example below was not the intended way to use CTH's but it works great for me!
First lets take a look at the table.
Next we continue by creating a plain old java object (POJO) to represent this table.
Now that the easy stuff is completed let connect both the database and the POJO together using iBatis.
As you can see there is nothing special that you need to do.
When working with a CLOB the only that the you need to change is the property in your bean. Just change byte to java.lang.String.
|Data size bigger than max size for this type: ????|
Some of the older jdbc drivers for Oracle have trouble with Strings that are larger then 4k. The first step to correct this issue it to get a jdbc driver from Oracle that is newer then 10g Release 2. This driver will work with both 9i and 10g databases. If you are stuck with an older driver you can try to set a driver property. The property is SetBigStringTryClob=true. If you are using the SimpleDataSource with iBatis use the follow line in the config file.
|Data size always 86 bytes?|
If you find that the length of your byte is always 86, check that you have the jdbcType="BLOB" or jdbcType="CLOB" in your result map.