Clob转String

阅读更多

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)