主题:用jsp编写图片浏览器!
vicent619
[专家分:0] 发布于 2007-04-05 20:52:00
由于毕业设计做的是这个,还请各位高手帮忙!就类似于windows图片查看程序一样!
谢谢了!
回复列表 (共1个回复)
沙发
mwsoft [专家分:760] 发布于 2007-04-18 11:43:00
Session s = null;
byte[] buffer = new byte[1];
buffer[0] = 1;
try {
Configuration ds = new
Configuration().configure("/hibernate.cfg.xml");
SessionFactory sf = ds.buildSessionFactory();
s = sf.openSession();
Transaction tx = s.beginTransaction();
ParentCatPO parentcat = new ParentCatPO();
parentcat.setName("老猫");
CatPO c = new CatPO();
c.setCatname("小猫1");
c.setImage(Hibernate.createBlob(buffer));
c.setParentcat(parentcat);
Set catlist = new HashSet();
catlist.add(c);
parentcat.setCats(catlist);
s.save(parentcat);
s.flush();
s.refresh(parentcat, LockMode.UPGRADE);
Iterator it = parentcat.getCats().iterator();
while (it.hasNext()) {
CatPO newcat = ( (CatPO) it.next());
BLOB blob = (BLOB) newcat.getImage();
OutputStream out = blob.getBinaryOutputStream();
String fileName = "oraclejdbc.jar";
File f = new File(fileName);
FileInputStream fin = new FileInputStream(f);
int count = -1, total = 0;
byte[] data = new byte[ (int) fin.available()];
fin.read(data);
out.write(data);
fin.close();
out.close();
}
s.flush();
tx.commit();
}
catch (ClassCastException e) {
e.printStackTrace();
}
catch (Exception e) {
e.printStackTrace();
}
finally {
if (s != null) {
try {
s.close();
}
catch (Exception e) {}
}
}
import java.sql.Blob;
public class CatPO {
private String catid;
private String parentid;
private String catname;
private ParentCatPO parentcat;
private Blob image;
public CatPO() {
}
public String getCatid() {
return catid;
}
public void setCatid(String catid) {
this.catid = catid;
}
public String getCatname() {
return catname;
}
public void setCatname(String catname) {
this.catname = catname;
}
public Blob getImage() {
return image;
}
public void setImage(Blob image) {
this.image = image;
}
public String getParentid() {
return parentid;
}
public void setParentid(String parentid) {
this.parentid = parentid;
}
public ParentCatPO getParentcat() {
return parentcat;
}
public void setParentcat(ParentCatPO parentcat) {
this.parentcat = parentcat;
}
我来回复