ssh整合后图片保存到数据库中

-------------------------action------------------------------

public class LizNewAction extends Action {
/*
  * Generated Methods
  */
private LizDao lizdao;
private ImageVo imageVo;
InputStream is;
/**
  * Method execute
  * @param mapping
  * @param form
  * @param request
  * @param response
  * @return ActionForward
  */
public ActionForward execute(ActionMapping mapping, ActionForm form,
   HttpServletRequest request, HttpServletResponse response) {
  DynaActionForm lizNewForm = (DynaActionForm) form;// TODO Auto-generated method stub
  String moue=(String)lizNewForm.get("moue");
  FormFile file=(FormFile)lizNewForm.get("file");
  String id=(String)lizNewForm.get("id");
  
  try {
   is=file.getInputStream();
  
  
   System.out.println("*******************获得附件内容*******************");
  
   imageVo.setFileid(new Integer(id));
   imageVo.setFilename(file.getFileName());
   imageVo.setMoue(moue);
   imageVo.setFilecontext(is);
   Date date=new Date();
   String name=date.getDay()+date.getHours()+date.getMinutes()+"";
   OutPoint op=new OutPoint();
   String filepath=op.writer(imageVo.getFilecontext(), file.getFileName(), name);
   System.out.println("*******************存入表对象中*******************");
   if(lizdao.insert(imageVo))
   {
    
    request.setAttribute("id", imageVo.getFileid()+"");
    
    return mapping.findForward("success");
   }
  } catch (FileNotFoundException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } catch (IOException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  return mapping.findForward("filed");
}

public LizDao getLizdao() {
  return lizdao;
}
public void setLizdao(LizDao lizdao) {
  this.lizdao = lizdao;
}
public ImageVo getImageVo() {
  return imageVo;
}
public void setImageVo(ImageVo imageVo) {
  this.imageVo = imageVo;
}
}



-------------------------------DAO----------------------


public class LizDao extends HibernateDaoSupport
{
PreparedStatement ps;
public boolean insert(ImageVo image) {
  try {
   String sql="insert into Image1(fileid,filename,moue,filecontext) value(?,?,?,?)";
   Session session=this.getSession();
   Transaction tran=session.beginTransaction();
   ps=session.connection().prepareStatement(sql);
   ps.setInt(1,image.getFileid());
   ps.setString(2,image.getFilename());
   ps.setString(3, image.getMoue());
   ps.setBinaryStream(4, image.getFilecontext(), image.getFilecontext().available());
   ps.execute();
   tran.commit();
   session.close();
   ps.close();
   System.out.println("*******************储存成功*******************");
   return true;
  } catch (Exception e) {
   e.printStackTrace();
   return false;
  }
}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值