2012年11月23日

来源:互联网 发布:td 数据超出省略号 编辑:程序博客网 时间:2024/05/11 02:28
package net.hys.reg.util;

import java.io.Reader;
import java.sql.Clob;

public class DBUtil {
    
    public finalstatic String clob2String(Clob clob)
    {
     if (clob == null)
     {
       return null;
     }
    
     StringBuffer sb = new StringBuffer(65535);//64K
     Reader clobStream = null;//创建一个输入流对象
     try
     {
       clobStream = clob.getCharacterStream();
       char[] b = new char[60000];//每次获取60K
       int i = 0;
       while((i = clobStream.read(b)) != -1)
       {
         sb.append(b,0,i);
       }
     }
     catch(Exception ex)
     {
       sb = null;
     }
     finally
     {
       try
       {
         if (clobStream != null)
           clobStream.close();
       }
       catch (Exception e)
       {
       }
     }
     if (sb == null)
       return null;
     else
       return sb.toString();
    }
}
//row是一个对象(JAVABEAN)类
有个private String topic 属性;
rs 是一个ResultSet
 row.setTopic(DBUtil.clob2String((Clob)rs.getClob("topic")));
0 0
原创粉丝点击