Ibatis and Oracle CLOB
To use a CLOB in your Ibatis typehandler you can use the following code:
public void setParameter(ParameterSetter setter, Object parameter)throws SQLException{
...
oracle.sql.CLOB clob = oracle.sql.CLOB.getEmptyCLOB();
clob.setString(1, "Your String");
...
}
To extract a CLOB with utf-8 support:
public Object getResult(ResultGetter getter) {
STRUCT struct = (STRUCT) getter.getObject();
oracle.sql.CLOB clob = (oracle.sql.CLOB) struct.getAttributes()[1];
String line;
StringBuilder sb = new StringBuilder();
try {
//make sure to use getCharacterStream and not getASCIStream so special characters are supported
BufferedReader reader = new BufferedReader(clob.getCharacterStream());
while ((line = reader.readLine()) != null) {
sb.append(line).append("n");
}
}

Comments are closed.