Oracle中Clob类型的字段数据转换成String字符串

时间:2021-12-21 00:50:50

具体函数如下:

//clob 转换 String (传入 clob 类型的 obj 对象)
public static String getClob2String(Object obj) {
String str = "";
try {
CLOB clob = (CLOB) obj;
if (clob == null || clob.length() == 0) {
str = "";
} else {
long clen = clob.length();
char clobArray[] = new char[(int) clen];
int readednum = clob.getChars(1, (int) clen, clobArray);
StringBuffer sb = new StringBuffer();
sb.append(clobArray);
str = sb.toString();
}
} catch (SQLException e) {
e.printStackTrace();
}
return str;
}