下面的程序总是给出异常
"java.sql.SQLRecoverableException: Closed Connection" in this line of " final Reader reader = clb.getCharacterStream();"
import java.io.BufferedReader;
import java.io.IOException;
import java.io.Reader;
import java.sql.Clob;
import java.sql.SQLException;
public class ClobStringConversion {
public static String clobStringConversion(Clob clb) throws IOException, SQLException
{
if (clb == null)
return "";
StringBuffer sb = new StringBuffer();
String strng;
try{
final Reader reader = clb.getCharacterStream();
final BufferedReader br = new BufferedReader(reader);
int b;
while(-1 != (b = br.read()))
{
sb.append((char)b);
}
br.close();
}
catch (SQLException e)
{
//log.error("SQL. Could not convert CLOB to string",e);
return e.toString();
}
catch (IOException e)
{
//log.error("IO. Could not convert CLOB to string",e);
return e.toString();
}
return sb.toString();
}
}
最佳答案
您可能在调用clobStringConversion()
之前关闭连接。尝试在读取 Clob 后关闭连接。
关于java - CLOB 到字符串转换 + java 1.8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44335742/