« | September 2025 | » | 日 | 一 | 二 | 三 | 四 | 五 | 六 | | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | | | | | |
| 公告 |
|
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; } |
|
|