欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Clob转String 博客分类: JavaSE clobstring 

程序员文章站 2024-03-06 15:03:32
...

java.sql.Clob转String

public static String clob2String(Object clobObj) {
		if (clobObj != null && clobObj instanceof Clob) {
			Clob clob = (Clob)clobObj;
			String reString = "";
	        try {
				Reader is = clob.getCharacterStream();
				// 得到流
				BufferedReader br = new BufferedReader(is);
				String s = br.readLine();
				StringBuffer sb = new StringBuffer();
				while (s != null) {
				    //执行循环将字符串全部取出付值给StringBuffer由StringBuffer转成STRING
				    sb.append(s);
				    s = br.readLine();
				}
				reString = sb.toString();
			} catch (Exception e) {
				log.error("transfer clob to string error!" + e);
			}
	        
	        return reString;
		}
        
		return null;
	}

 

相关标签: clob string