Ibatis and Oracle BLOB
Usage of the typehandler inserting a byte[] into the database
public void setParameter(ParameterSetter setter, Object parameter)throws SQLException{
…
byte[] bytesToBeInserted = (byte[]) parameter;
oracle.sql.BLOB blob = oracle.sql.BLOB.getEmptyBLOB();
blob.setBytes(bytesToBeInserted);
...
setter.setBlob(blob);
}
Transforming a BLOB to a byte[] using an Ibatis typehandler
public Object getResult(ResultGetter getter) throws SQLException {
oracle.sql.BLOB blob = (oracle.sql.BLOB) getter.getBlob();
byte[] bytes = blob.getBytes(0, blob.getLength());
return bytes;
}

Comments are closed.