您的位置:首页 > 数据库 > Oracle

java程序处理oracle的clob对象

2015-10-30 17:17 519 查看
摘要: 利用spring+ibatis,插入,查看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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: