2017-06-02 60 views
0

以下程序总是给异常CLOB到字符串转换+的java 1.8

“java.sql.SQLRecoverableException:关闭连接”在此行中的“最后阅读器读取器= 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

您应该提供更多详细信息,例如您正在使用的数据库,JDBC驱动程序,CLOB的预期长度,这是间歇性还是每次都发生。 – 11thdimension

+0

当前使用Oracle数据库和jdbc驱动程序。 CLOB长度非常大。 – Ravikanth

+1

如果您希望获得帮助,则需要提供更多代码。此错误消息表明,到目前为止,套接字连接已关闭;您无法从封闭流中读取数据。我们在这里无能为力。 –

回答

1

你可能会关闭调用clobStringConversion()之前的连接。尝试在阅读Clob后关闭连接。