Reputation: 4135
The below program is always giving the exception
"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();
}
}
Upvotes: 0
Views: 3252
Reputation: 499
You are probably closing the connection before calling clobStringConversion()
. Try closing the connection after reading the Clob.
Upvotes: 1