hibernate操作 oracle clob字段


Clob content = almanacBean.getContributionContent();
almanacBean.setContenteStr(content.getSubString(1, (int)content.length()));


Action 层以String传过来

DAO:

public TbAlmanacContribution savaTbAlmanacContribution(final TbAlmanacContribution tbAlmanacContribution)
2. {
3. HibernateCallback callback = new HibernateCallback()
4. {
5. public Object doInHibernate(Session session) throws HibernateException, SQLException
6. {
7. String content=tbAlmanacContribution.getContenteStr();//获取传过来的string
8. TbAlmanacContribution temp = tbAlmanacContribution;
9. temp.setContributionContent(Hibernate.createClob(" "));//首先插入一个空的clob对象
10. session.saveOrUpdate(temp);//保存
11. session.flush();
12. session.refresh(temp, LockMode.UPGRADE);
13. try
14. {
15. SerializableClob sc= (SerializableClob)temp.getContributionContent();//序列化成clob
16. Clob wrapclob = sc.getWrappedClob();
17. if(wrapclob instanceof CLOB){
18. CLOB clob = (CLOB)wrapclob;
19.// clob = (oracle.sql.CLOB) temp.getContributionContent();
20.// clob.putString(1,content);
21. java.io.Writer writer = clob.getCharacterOutputStream();
22. writer.write(content);
23. writer.close();
24. }
25.
26.// session.saveOrUpdate(temp);
27.// tx.commit();
28.
29. } catch(Exception e)
30. {
31. e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
32. }
33. return temp;
34. }
35. };
36. return (TbAlmanacContribution) getHibernateTemplate().execute(callback);
37. }

读取
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值