Joined: Tue May 15, 2007 2:54 am Posts: 4
|
I found the solution. Here i m sharing the code.
FileInputStream fis=new FileInputStream(file);
byte b[] = new byte[fis.available()];
fis.read(b);
java.sql.Blob bb = Hibernate.createBlob(b);
TblobForm tblob = new TblobForm();
tblob.setfiledata(bb);
tblob.setId(1);
fis.close();
session.save(tblob);
I have 2 field id and photo
id is of type integer
filedata is of type blob.
And to retrieve from the database:
TblobForm form = new TblobForm();
byte b[] = form.getFileData().getBytes(1,(int)form.getFileData().length());
java.io.FileOutputStream f = new java.io.FileOutputStream(filename);
f.write(b);
I hope this will help u all.
|
|