Hibernate 操作CLOb

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

 Action 层以String传过来

 

DAO:

 public TbAlmanacContribution savaTbAlmanacContribution(final TbAlmanacContribution tbAlmanacContribution)
    {
        HibernateCallback callback = new HibernateCallback()
        {
            public Object doInHibernate(Session session) throws HibernateException, SQLException
            {
                 String content=tbAlmanacContribution.getContenteStr();//获取传过来的string
                TbAlmanacContribution temp = tbAlmanacContribution;
                temp.setContributionContent(Hibernate.createClob(" "));//首先插入一个空的clob对象
                session.saveOrUpdate(temp);//保存
                session.flush();
                session.refresh(temp, LockMode.UPGRADE);
                try
                {
                    SerializableClob  sc= (SerializableClob)temp.getContributionContent();//序列化成clob
                    Clob wrapclob = sc.getWrappedClob();
                    if(wrapclob instanceof CLOB){
                        CLOB clob = (CLOB)wrapclob;
//                    clob = (oracle.sql.CLOB) temp.getContributionContent();
//                    clob.putString(1,content);
                        java.io.Writer writer = clob.getCharacterOutputStream();
                        writer.write(content);
                         writer.close();
                    }

//                      session.saveOrUpdate(temp);
//                    tx.commit();

                } catch(Exception e)
                {
                    e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
                }
                return temp;
            }
        };
        return (TbAlmanacContribution) getHibernateTemplate().execute(callback);
    }

 读取

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值