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

Java实现Clob类型转String

程序员文章站 2022-06-18 20:22:17
...
	public String clobToString(Clob clob) throws Exception {
        String re = "";
        Reader is = null;
        BufferedReader br = null;
        try {			
        	// 得到流
        	is = clob.getCharacterStream();
        	br = new BufferedReader(is);
        	String s = br.readLine();
        	StringBuffer sb = new StringBuffer();
        	// 执行循环将字符串全部取出付值给StringBuffer由StringBuffer转成STRING
        	while (s != null) {
        		sb.append(s);
        		s = br.readLine();
        	}
        	re = sb.toString();
		} catch (Exception e) {
        	e.printStackTrace();
		}finally {
			if (is != null) {
				is.close();
			}
			if (br != null) {
				br.close();
			}
		}
        return re;
    }
String clobString = clob.getSubString(1, (int) clob.length());
String blobString = new String(blob.getBytes(1, (int) blob.length()),"GBK");
相关标签: Java java