以下程序始终提供例外
“java.sql.SQLRecoverableException:Closed Connection”在这行“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();
}
}
答案 0 :(得分:1)
您可能在致电clobStringConversion()
之前关闭了连接。尝试阅读Clob后关闭连接。