Oracle clob处理
2015-11-11 03:06
495 查看
for (int i=0;i<noticeResult.getResult().size();i++) {
CLOB clob = (CLOB) noticeResult.getResult().get(i).get("NOTICE_CONTENT");
String content = "";
try {
if (clob != null && clob.length() != 0) {
content = clob.getSubString((long) 1, (int) clob.length());
content = this.Clob2String(clob);
}
} catch (SQLException e) {
e.printStackTrace();
}
System.out.println("NOTICE_CONTENT:"+content);
}
private String Clob2String(CLOB clob) {
String content = null;
StringBuffer stringBuf = new StringBuffer();
try {
int length = 0;
Reader inStream = clob.getCharacterStream(); // 取得大字侧段对象数据输出流
char[] buffer = new char[10];
while ((length = inStream.read(buffer)) != -1) // 读取数据库 //每10个10个读取
{
for (int i = 0; i < length; i++) {
stringBuf.append(buffer[i]);
}
}
inStream.close();
content = stringBuf.toString();
} catch (Exception ex) {
System.out.println("ClobUtil.Clob2String:" + ex.getMessage());
}
return content;
}
<resultMap id="noticeResult" type="java.util.Map">
<result property="NOTICE_ID" column="NOTICE_ID" javaType="int" jdbcType="INTEGER"/>
<result property="NOTICE_TITLE" column="NOTICE_TITLE" javaType="string" jdbcType="VARCHAR"/>
<result property="NOTICE_TYPE" column="NOTICE_TYPE" javaType="int" jdbcType="INTEGER" />
<result property="NOTICE_CONTENT" column="NOTICE_CONTENT" jdbcType="CLOB" javaType = "java.lang.String" />
<result property="NOTICE_URL_NAME" column="NOTICE_URL_NAME" javaType="string" jdbcType="VARCHAR"/>
<result property="NOTICE_SHOW_NAME" column="NOTICE_SHOW_NAME" javaType="string" jdbcType="VARCHAR"/>
<result property="NOTICE_STATUS" column="NOTICE_STATUS" javaType="int" jdbcType="INTEGER" />
<result property="CREATE_USER_ID" column="CREATE_USER_ID" javaType="int" jdbcType="INTEGER"/>
<result property="CREATE_TIME" column="CREATE_TIME" javaType="java.sql.Timestamp" jdbcType="DATE"/>
<result property="ADMIN_PRC" column="ADMIN_PRC" javaType="string" jdbcType="VARCHAR"/>
</resultMap>
<parameterMap id="noticePara" type="com.hp.pfm.salt.domain.Notice">
<parameter property="noticeId" jdbcType="INTEGER" javaType ="java.lang.Integer"/>
<parameter property="noticeTitle" jdbcType="VARCHAR" javaType ="java.lang.String"/>
<parameter property="noticeType" jdbcType="INTEGER" javaType ="java.lang.Integer"/>
<parameter property="noticeContent" jdbcType="CLOB" javaType ="java.lang.String"/>
<parameter property="noticeUrlName" jdbcType="VARCHAR" javaType ="java.lang.String"/>
<parameter property="noticeShowName" jdbcType="VARCHAR" javaType ="java.lang.String"/>
<parameter property="noticeStatus" jdbcType="INTEGER" javaType ="java.lang.Integer"/>
<parameter property="createUserId" jdbcType="INTEGER" javaType ="java.lang.Integer"/>
<parameter property="createTime" jdbcType="DATE" javaType ="java.sql.Date"/>
</parameterMap>
转载自:http://blog.csdn.net/kiss_vicente/article/details/9214051
CLOB clob = (CLOB) noticeResult.getResult().get(i).get("NOTICE_CONTENT");
String content = "";
try {
if (clob != null && clob.length() != 0) {
content = clob.getSubString((long) 1, (int) clob.length());
content = this.Clob2String(clob);
}
} catch (SQLException e) {
e.printStackTrace();
}
System.out.println("NOTICE_CONTENT:"+content);
}
private String Clob2String(CLOB clob) {
String content = null;
StringBuffer stringBuf = new StringBuffer();
try {
int length = 0;
Reader inStream = clob.getCharacterStream(); // 取得大字侧段对象数据输出流
char[] buffer = new char[10];
while ((length = inStream.read(buffer)) != -1) // 读取数据库 //每10个10个读取
{
for (int i = 0; i < length; i++) {
stringBuf.append(buffer[i]);
}
}
inStream.close();
content = stringBuf.toString();
} catch (Exception ex) {
System.out.println("ClobUtil.Clob2String:" + ex.getMessage());
}
return content;
}
<resultMap id="noticeResult" type="java.util.Map">
<result property="NOTICE_ID" column="NOTICE_ID" javaType="int" jdbcType="INTEGER"/>
<result property="NOTICE_TITLE" column="NOTICE_TITLE" javaType="string" jdbcType="VARCHAR"/>
<result property="NOTICE_TYPE" column="NOTICE_TYPE" javaType="int" jdbcType="INTEGER" />
<result property="NOTICE_CONTENT" column="NOTICE_CONTENT" jdbcType="CLOB" javaType = "java.lang.String" />
<result property="NOTICE_URL_NAME" column="NOTICE_URL_NAME" javaType="string" jdbcType="VARCHAR"/>
<result property="NOTICE_SHOW_NAME" column="NOTICE_SHOW_NAME" javaType="string" jdbcType="VARCHAR"/>
<result property="NOTICE_STATUS" column="NOTICE_STATUS" javaType="int" jdbcType="INTEGER" />
<result property="CREATE_USER_ID" column="CREATE_USER_ID" javaType="int" jdbcType="INTEGER"/>
<result property="CREATE_TIME" column="CREATE_TIME" javaType="java.sql.Timestamp" jdbcType="DATE"/>
<result property="ADMIN_PRC" column="ADMIN_PRC" javaType="string" jdbcType="VARCHAR"/>
</resultMap>
<parameterMap id="noticePara" type="com.hp.pfm.salt.domain.Notice">
<parameter property="noticeId" jdbcType="INTEGER" javaType ="java.lang.Integer"/>
<parameter property="noticeTitle" jdbcType="VARCHAR" javaType ="java.lang.String"/>
<parameter property="noticeType" jdbcType="INTEGER" javaType ="java.lang.Integer"/>
<parameter property="noticeContent" jdbcType="CLOB" javaType ="java.lang.String"/>
<parameter property="noticeUrlName" jdbcType="VARCHAR" javaType ="java.lang.String"/>
<parameter property="noticeShowName" jdbcType="VARCHAR" javaType ="java.lang.String"/>
<parameter property="noticeStatus" jdbcType="INTEGER" javaType ="java.lang.Integer"/>
<parameter property="createUserId" jdbcType="INTEGER" javaType ="java.lang.Integer"/>
<parameter property="createTime" jdbcType="DATE" javaType ="java.sql.Date"/>
</parameterMap>
转载自:http://blog.csdn.net/kiss_vicente/article/details/9214051
相关文章推荐
- Java 对Oracle Clob(大字符串)格式的操作 增改查
- ORACLE 操作 CLOB 字段
- Mybatis之Oracle增删查改示例(含Date、Clob数据类型操作)
- 重庆oracle OCM认证培训-甲骨文重庆思庄100%通过率
- Oracle触发器调用存储过程示例
- 关于Oracle事务的总结
- Oracle查询二
- Oracle查询
- ORACLE安装与操作系统用户组说明
- oracle plsql语句、游标
- oracle 锁表与解锁、数据恢复
- oracle触发器
- oracle函数大全
- 20151110 oracle事务 redo undo
- oracle的内置函数
- oracle用户创建及权限设置
- Oracle 通过sql profile为sql语句加hint
- with as与hint materialize的使用
- Oracle ORA-02020 : 过多的数据库链接
- Oracle自增列创建方法