Oracle clob处理

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>

你可能感兴趣的:(Oracle clob处理)