本站首页    管理页面    写新日志    退出


«September 2025»
123456
78910111213
14151617181920
21222324252627
282930


公告

 


我的分类(专题)

日志更新

最新评论

留言板

链接

Blog信息
blog名称:
日志总数:22
评论数量:55
留言数量:0
访问次数:129559
建立时间:2006年3月13日




操作blob与clob
软件技术

jjs_love 发表于 2007/3/22 10:13:27

 clob public void addArmynews(Armynews armynews, String clobstr) {         Session session =this.getSession();         Transaction tran = session.beginTransaction();  try{       armynews.setContent(Hibernate.createClob(" ")); //插入一个空的       session.save(armynews);       session.flush();       session.refresh(armynews,LockMode.UPGRADE);             SerializableClob  sc = (SerializableClob)armynews.getContent();             Clob wrapclob = sc.getWrappedClob();             CLOB clob = (CLOB)wrapclob;             clob.putString(1,clobstr);             tran.commit();             }catch(Exception ex){                    ex.printStackTrace();                    tran.rollback();                                              }                  }   public void editInform(Inform inform,String clobstr) {        Session session =this.getSession();   Transaction tran = session.beginTransaction();     try{        Inform temp=(Inform) session.load(Inform.class,inform.getId());       temp.setContent(Hibernate.createClob(" "));       temp.setTime1(inform.getTime1());       temp.setTitle(inform.getTitle());    session.flush();    session.refresh(temp,LockMode.UPGRADE);              SerializableClob  sc = (SerializableClob)temp.getContent();          Clob wrapclob = sc.getWrappedClob();          CLOB clob = (CLOB)wrapclob;          clob.putString(1,clobstr);          tran.commit();    }catch(Exception e){    tran.rollback();    System.out.print(e.getMessage()+"ok");   } }  public Armynews findArmynewsID(Long id) {  Session session =this.getSession();  Armynews result=(Armynews) session.get(Armynews.class,id);  java.sql.Clob clob=result.getContent();  try{           String str=clob.getSubString(1, (int) clob.length());           result.setClobstr(str);         }catch(Exception e){         System.out.print("Error_clob:"+e.getMessage());        }     return result; }blob 映射成byte[]类型直接保存就是了 读取图  public ActionForward gethot(   ActionMapping mapping,   ActionForm form,   HttpServletRequest request,   HttpServletResponse response)  {    try{   BufferedOutputStream buffout = new BufferedOutputStream(response.getOutputStream());         List list=armynewsDAO.findHotArmynews();        Armynews armynews=new Armynews();       armynews=(Armynews) list.get(0);       byte[] buff = armynews.getPic();       buffout.write(buff);      buffout.close();  }catch(Exception e){   System.out.print(e.getMessage());  }finally{    }    return  null;  }


阅读全文(2076) | 回复(0) | 编辑 | 精华
 



发表评论:
昵称:
密码:
主页:
标题:
验证码:  (不区分大小写,请仔细填写,输错需重写评论内容!)



站点首页 | 联系我们 | 博客注册 | 博客登陆

Sponsored By W3CHINA
W3CHINA Blog 0.8 Processed in 0.031 second(s), page refreshed 144773770 times.
《全国人大常委会关于维护互联网安全的决定》  《计算机信息网络国际联网安全保护管理办法》
苏ICP备05006046号