commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Manuel" <man...@ilch.de>
Subject Re: [DBUTILS] BeanHandler plus Blob
Date Sat, 16 Oct 2010 05:51:26 GMT
Hi,

just if some else have similar problem... found the solution myself.

Overwrite BeanProcessor

public class MyBeanProcessor extends BeanProcessor {
  @Override
  rotected Object processColumn(ResultSet rs, int index, Class<?>
propType) throws SQLException {
    if (propType.equals(ImageIcon.class)) {
      return getImageIcon(rs.getBlob(index));
    }

    return super.processColumn(rs, index, propType);
  }
}

Create ResultSetHandler like that:

ResultSetHandler<Person> h = new BeanHandler<Person>(Person.class, new
BasicRowProcessor(new MyBeanProcessor()));

That would do the job, now you can map a blob to an ImageIcon.
You can implement other special type the same way!

Greetings Manuel


Am Fr, 15.10.2010, 09:06 schrieb Manuel:
> Hi,
>
> have a class
>
> public class Person {
>   private Blob image;
>   public void setImage(Blob image) { this.image = image; }
>   public Blob getImage() { return image; }
> }
>
> Now I want to load the Person-class with BeanHandler-class
> ResultSetHandler<Person> h = new BeanHandler<Person>(Person.class);
> Person person = runner.query("select image from ...", h);
>
> Works so far :-) Now what not works:
>
> person.getImage();
> ObjectInputStream ois = null;
> ois = new ObjectInputStream(blob.getBinaryStream());
> ImageIcon icon = (ImageIcon) ois.readObject();
>
> -> Exception
> You cannot invoke other java.sql.Clob/java.sql.Blob methods after calling
> the free() method or after the Blob/Clob's transaction has been committed
> or rolled back.
>
> Do the query myself, or and write a own BeanHandler...
> But shouldn't there a solution to just say
> 1.) write blob data in a stream x
> 2.) write blob data to an object x
>
> OR ... go the other way, means change Person class to have an object let's
> say instead Blob and ImageIcon and tell dbutils how to map from blob to
> ImageIcon...
>
> thanks for any response in advance ;)
>
> greetings manuel
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message