六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 254|回复: 0

hibernate操作 oracle clob字段

[复制链接]

升级  44%

6

主题

6

主题

6

主题

童生

Rank: 1

积分
22
 楼主| 发表于 2013-1-29 15:25:08 | 显示全部楼层 |阅读模式
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.    }  
读取
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表