CLOB to String conversion + java 1.8

时间:2017-06-02 18:58:22

标签: java

以下程序始终提供例外

  

“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();
    }     

}

1 个答案:

答案 0 :(得分:1)

您可能在致电clobStringConversion()之前关闭了连接。尝试阅读Clob后关闭连接。

相关问题