Clob To String - Java java.sql

Java examples for java.sql:Clob

Description

Clob To String

Demo Code


//package com.java2s;
import java.io.BufferedReader;
import java.io.IOException;
import java.sql.Clob;
import java.sql.SQLException;

public class Main {
    public static String ClobToString(Clob cl) throws IOException,
            SQLException {/* w w w  .j a  va2  s. co  m*/
        if (cl == null)
            return "";

        StringBuffer strOut = new StringBuffer();
        String aux;

        // We access to stream, as this way we don't have to use the CLOB.length() which is slower...
        BufferedReader br = new BufferedReader(cl.getCharacterStream());

        while ((aux = br.readLine()) != null)
            strOut.append(aux);

        return strOut.toString();
    }
}

Related Tutorials