/**
* 将数据库中Clob类型转换成java的String类型
* @param clob
* @return
* @throws SQLException
*/
public static String clobtoString(Clob clob) throws SQLException {
StringBuffer str = new StringBuffer();
if (clob == null) {
return null;
}
Reader reader = null;
try {
reader = clob.getCharacterStream();
char ac[] = new char[200];
int i;
while ((i = reader.read(ac, 0, 200)) != -1) {
str.append(new String(ac, 0, i));
}
} catch (Exception exception1) {
throw new SQLException(exception1.getMessage());
} finally {
try {
reader.close();
} catch (Exception _ex) {
}
}
return str.toString();
* 将数据库中Clob类型转换成java的String类型
* @param clob
* @return
* @throws SQLException
*/
public static String clobtoString(Clob clob) throws SQLException {
StringBuffer str = new StringBuffer();
if (clob == null) {
return null;
}
Reader reader = null;
try {
reader = clob.getCharacterStream();
char ac[] = new char[200];
int i;
while ((i = reader.read(ac, 0, 200)) != -1) {
str.append(new String(ac, 0, i));
}
} catch (Exception exception1) {
throw new SQLException(exception1.getMessage());
} finally {
try {
reader.close();
} catch (Exception _ex) {
}
}
return str.toString();
}
private void mian() {
//map为数据库信息
String content_xml = StringUtil.clobtoString((Clob)map.get("content_xml"));
}
本文介绍了一种将数据库中的Clob类型数据转换为Java String类型的实用方法。通过使用字符流和缓冲区读取的方式,该方法能有效处理大型文本数据,确保数据完整迁移。
4563

被折叠的 条评论
为什么被折叠?



