get String from Clob - Java java.sql

Java examples for java.sql:Clob

Description

get String from Clob

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 getString(Clob c) {
        StringBuffer s = new StringBuffer();
        if (c != null) {
            try {
                BufferedReader bufferRead = new BufferedReader(
                        c.getCharacterStream());
                try {
                    String str;/*from  ww w.  j  av  a  2  s. c  om*/
                    while ((str = bufferRead.readLine()) != null) {
                        s.append(str);
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        return s.toString();
    }
}

Related Tutorials