java程序处理oracle的clob对象

ibatis 主配置文件SqlMapConfig.xml

   <typeHandler jdbcType="CLOB" javaType="java.lang.String"  callback="org.springframework.orm.ibatis.support.ClobStringTypeHandler" /> 


ArticleColumnDymanic配置文件:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMap      
    PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"      
    "http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMap namespace="ArticleColumnDymanic">
    <typeAlias alias="ArticleColumnDymanic" type="com.test.ArticleColumnDymanic" />

<resultMap class="ArticleColumnDymanic" id="ArticleColumnDymanicResult">
        <result property="id" column="i_id" />
        <result property="name" column="vc_name" />
        <result property="servletUrl" column="vc_url" />
        <result property="filePath" column="vc_filePath" />
        <result property="file" column="vc_file" />
        <result property="content" column="b_content" jdbcType="CLOB" />
        <result property="desc" column="vc_desc" />
        <result property="num" column="i_num" />
        <result property="base.createTime" column="d_createtime" />
        <result property="base.createUser" column="i_createuser" />
        <result property="base.lastModTime" column="d_lastmodtime" />
        <result property="base.modUser" column="i_moduser" />
        <result property="base.deleted" column="c_deleted" />
        <result property="version" column="vc_version" />
        <result property="isnew" column="vc_isnew" />
        <result property="vid" column="vc_id" />
        <result property="remark" column="vc_remark" />
    </resultMap>


<insert id="insertArticleColumnDymanic" parameterClass="ArticleColumnDymanic">
      <selectKey keyProperty="id" resultClass="long">   
         select seq_article.nextVal from dual   
      </selectKey>
        insert into tb_article_columndymanic( i_id,vc_name,vc_url,vc_filePath,vc_file,b_content,vc_desc,i_num,d_createtime,i_createuser,d_lastmodtime,i_moduser,c_deleted,vc_version,vc_isnew,vc_id,vc_remark)
        values (#id#,#name#,#servletUrl#,#filePath#,#file#,#content,handler=org.springframework.orm.ibatis.support.ClobStringTypeHandler#,#desc#,#num#,sysdate,#base.createUser#,sysdate,#base.modUser#,'0',#version#,#isnew#,
        <isNull property="vid"> #id# </isNull>
        <isNotNull property="vid">  #vid# </isNotNull> ,#remark#)
</insert>


<update id="updateArticleColumnDymanic" parameterClass="ArticleColumnDymanic">
        update tb_article_columndymanic
        set vc_name=#name#,vc_url=#servletUrl#,vc_filePath=#filePath#,vc_file=#file#,
 b_content=#content,handler=org.springframework.orm.ibatis.support.ClobStringTypeHandler#,vc_desc=#desc#,i_num=#num#,
        <isEqual property="isnew" compareValue="1">
                d_lastmodtime=sysdate,i_moduser=#base.modUser#,
            </isEqual>
            vc_version=#version#,vc_isnew=#isnew#,vc_id=#vid#,vc_remark=#remark#
        where i_id=#id#
  </update>

</sqlMap>


实体类:

public class ArticleColumnDymanic {

    private String name="";
    private String servletUrl="";
    private String filePath="";
    private String file="";
    private String content="";
    private String desc="";
    private int num=0;
    private Long version=new Long(1);
    private String isnew="1";
    private Long vid;
    private String remark;
    
    
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getServletUrl() {
        return servletUrl;
    }

    public void setServletUrl(String servletUrl) {
        this.servletUrl = servletUrl;
    }

    public String getFilePath() {
        return filePath;
    }

    public void setFilePath(String filePath) {
        this.filePath = filePath;
    }

    public String getFile() {
        return file;
    }

    public void setFile(String file) {
        this.file = file;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public int getNum() {
        return num;
    }

    public void setNum(int num) {
        this.num = num;
    }

    public Long getVersion() {
        return version;
    }

    public void setVersion(Long version) {
        this.version = version;
    }

    public String getIsnew() {
        return isnew;
    }

    public void setIsnew(String isnew) {
        this.isnew = isnew;
    }

    public Long getVid() {
        return vid;
    }

    public void setVid(Long vid) {
        this.vid = vid;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }
}



查询clob字段:

    <select id="selectContent" resultClass="java.util.HashMap" parameterClass="java.util.HashMap">
             select b_content
             from tb_article_info a,
             tb_article_fund b, tb_article_content c
             where a.i_articleid =
             b.i_articleid
             and a.i_articleid = c.i_articleid
             and i_columnid = '5908'
             and c.c_deleted='0'
             and a.c_deleted='0'
             and b.c_deleted='0'
             <isNotEmpty prepend="AND" property="fundCode">
                    vc_fundcode = #fundCode#
             </isNotEmpty>
      </select>

 public List<HashMap<String, String>> selectProductById(HashMap<String, String> map)
 {
   List listm = this.dao.findForList("selectProductById", map);
   if ((listm != null) && (listm.size() > 0)) {
     for (int i = 0; i < listm.size(); ++i) {
       HashMap hm = (HashMap)listm.get(i);
       CLOB clob = (CLOB)hm.get("B_CONTENT");
       try {
         hm.put("B_CONTENT", ClobToString(clob));
       }
       catch (Exception e) {
         e.printStackTrace();
       }
     }
   }

   return listm;
 }

 private static String ClobToString(CLOB clob) throws Exception {
   String reString = "";
   Reader is = clob.getCharacterStream();
   BufferedReader br = new BufferedReader(is);
   String s = br.readLine();
   StringBuffer sb = new StringBuffer();
   while (s != null) {
     sb.append(s);
     s = br.readLine();
   }
   reString = sb.toString();
   return reString;
 }



转载于:https://my.oschina.net/v512345/blog/524117

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值