Fckedit2.6存取oralce的clob类型

本来想用stream流读出clob类型数据到update页面中的,不知道什么原因是乱码
不过还好,clob类型有getSubString方法
model
创建一个用于存贮clob类型转化后的String属性
package com.zk.model.business;

import java.sql.Clob;
import java.sql.Date;

import oracle.sql.CLOB;

/**
 * Issueinfo entity. @author MyEclipse Persistence Tools
 */

public class Issueinfo implements java.io.Serializable {

	// Fields

	private String recid;
	private String title;
	private Date issuetim;
	private String infosort;
	private String worker;
	private Clob content;
	private String strContent;

	public String getStrContent() {
		return strContent;
	}

	public void setStrContent(String strContent) {
		this.strContent = strContent;
	}

	/** default constructor */
	public Issueinfo() {
	}

	/** minimal constructor */
	public Issueinfo(String recid) {
		this.recid = recid;
	}

	/** full constructor */
	public Issueinfo(String recid, String title, Date issuetim,
			String infosort, String worker, Clob content) {
		this.recid = recid;
		this.title = title;
		this.issuetim = issuetim;
		this.infosort = infosort;
		this.worker = worker;
		this.content = content;
	}

	// Property accessors

	public String getRecid() {
		return this.recid;
	}

	public void setRecid(String recid) {
		this.recid = recid;
	}

	public String getTitle() {
		return this.title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public Date getIssuetim() {
		return this.issuetim;
	}

	public void setIssuetim(Date issuetim) {
		this.issuetim = issuetim;
	}

	public String getInfosort() {
		return this.infosort;
	}

	public void setInfosort(String infosort) {
		this.infosort = infosort;
	}

	public String getWorker() {
		return this.worker;
	}

	public void setWorker(String worker) {
		this.worker = worker;
	}

	public Clob getContent() {
		return this.content;
	}

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

}
 model.xml
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- 
    Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
    <class name="com.zk.model.business.Issueinfo" table="ISSUEINFO" schema="PAWNSYS">
        <id name="recid" type="java.lang.String">
            <column name="RECID" length="12" />
            <generator class="assigned"></generator>
        </id>
        <property name="title" type="java.lang.String">
            <column name="TITLE" length="100" />
        </property>
        <property name="issuetim" type="java.sql.Date">
            <column name="ISSUETIM" length="7" />
        </property>
        <property name="infosort" type="java.lang.String">
            <column name="INFOSORT" length="1" />
        </property>
        <property name="worker" type="java.lang.String">
            <column name="WORKER" length="30" />
        </property>
        <property name="content" type="java.sql.Clob">
            <column name="CONTENT"/>
        </property>
    </class>
</hibernate-mapping>
  
Dao
对象写入库
public void addObj(Issueinfo obj) throws LException {
	try {
			Session session = this.getSession();
			Transaction tran = session.beginTransaction();
			obj.setContent(Hibernate.createClob(" "));// 注意,这里的参数是个空格,先新增一个空的Clob进去
			session.save(obj);
			session.flush();// 强制执行
			session.refresh(obj, LockMode.UPGRADE);
			SerializableClob sc = (SerializableClob) obj.getContent();// 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(obj.getStrContent());// kybasicInfo.getInfoContentToString()是String类型的,在action里就是传这个进来,然后再通过文件流形式写成CLOB字段中
			writer.close();
			session.save(obj);
			tran.commit();
		} catch (RuntimeException re) {
			throw re;
		} catch (SQLException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

 对象从库中取出

 

public Issueinfo getInfo(String recid, String infosort) throws LException {
		Session session = this.getSession();
		session.beginTransaction();
		Connection con = null;
		Statement st = null;
		ResultSet rs = null;
		Issueinfo is = new Issueinfo();
		try {
			con = session.connection();
			st = con.createStatement();

			rs = st.executeQuery("select * from issueinfo where recid='"
					+ recid + "' and infosort='" + infosort + "'");
			if (rs.next()) {
				Clob content = rs.getClob("CONTENT");//取出clob字段
				// clob转换成String			
				long longLen = content.length();//长度
				System.out.println(longLen);
				String rtn = content.getSubString(1L, (int) longLen);//通过此方法可以将clob以String方式输出
				is.setRecid(rs.getString("RECID"));
				is.setIssuetim(rs.getDate("ISSUETIM"));
				is.setInfosort(rs.getString("INFOSORT"));
				is.setTitle(rs.getString("TITLE"));
				is.setWorker(rs.getString("WORKER"));
				is.setStrContent(rtn);//存贮在临时属性中
				System.out.println(rtn);
			}

		} catch (SQLException e) { // TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			if (rs != null) {
				try {
					con.close();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			if (st != null) {
				try {
					con.close();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			if (con != null) {
				try {
					con.close();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			session.close();
		}
		return is;
	}

 view

在取出strContent时注意

<s:property value="" />默认输入是过滤html

加上escape=false,html字符串转化为html输入

									<FCK:editor instanceName="content" toolbarSet="My" width="660"
										height="400">

										<jsp:attribute name="value">

								
					   				<s:property value="isinfo.strContent" escape="false" />
					   				
					   	 			</jsp:attribute>

									</FCK:editor>

 

 

 

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值