• oracle数据库里保存clob字段


    public void addStatements(StatementsBean statementsBean) {
    try {
    Session session = this.getSession();
        Transaction tran=session.beginTransaction();
        statementsBean.setStatementsContent(Hibernate.createClob(" "));//注意,这里的参数是个空格,先新增一个空的Clob进去
        session.save(statementsBean);
        session.flush();//强制执行
        session.refresh(statementsBean,LockMode.UPGRADE);

        SerializableClob sc=(SerializableClob)statementsBean.getStatementsContent();//kybasicInfo.getInfoContent()是Clob类型的
        Clob wrapclob=sc.getWrappedClob();//这里的Clob是java.sql.Clob
        CLOB clob=(CLOB)wrapclob;//这里的CLOB是oracle.sql.CLOB
        Writer writer=clob.getCharacterOutputStream();
        writer.write(statementsBean.getContentToString());//kybasicInfo.getInfoContentToString()是String类型的,在action里就是传这个进来,然后再通过文件流形式写成CLOB字段中
        writer.close();

        session.save(statementsBean);
        tran.commit();
      
       } catch (RuntimeException re) {
        throw re;
       } catch (SQLException e) {
        e.printStackTrace();
       } catch (IOException e) {
        e.printStackTrace();
       }



    }
  • 相关阅读:
    LeetCode120 Triangle
    LeetCode119 Pascal's Triangle II
    LeetCode118 Pascal's Triangle
    LeetCode115 Distinct Subsequences
    LeetCode114 Flatten Binary Tree to Linked List
    LeetCode113 Path Sum II
    LeetCode112 Path Sum
    LeetCode111 Minimum Depth of Binary Tree
    Windows下搭建PHP开发环境-WEB服务器
    如何发布可用于azure的镜像文件
  • 原文地址:https://www.cnblogs.com/harbin1900/p/8480989.html
Copyright © 2020-2023  润新知