Pretty simple question with almost no answers on the web. I am using byte[] as my object. Currently I am reading the entire image into memory and then writing it. Very simple.
@Column(name = "FILE_DATA")
private byte[] fileData;
I want to Stream it in. So I guess I need to use inputStream, but hibernate does not like that.
How do I set this up?
EDIT:
I tried this but got a -314 db2 error:
Blob b = null;
try {
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("proxy.com", 80));
URL urls = new URL(url);
URLConnection conn = urls.openConnection(proxy);
b = new BlobImpl(conn.getInputStream(), conn.getContentLength());
} catch (Exception e) {
e.printStackTrace();
}
att.setFileData(b);
this.theDao.save(att);
You can use Blob data type for inserting and fetching the images from database. It wil also provide you the option of Binary input stream. Just Use your db field as blob and create a blob ojbect instead of byte array.
Also you can create Blob from
bytes[]And the simplest solution Saving on the hard drive and keeping information about the image on database.