Function to convert clob to string - Java JDBC

Java examples for JDBC:Binary Data

Description

Function to convert 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 {
    /**//  www. j a v a 2s .  co m
     * Function to convert clob to string
     * @param clob
     * @return
     * @throws SQLException
     * @throws IOException
     */
    public static String getClobString(Clob clob) throws SQLException,
            IOException {
        BufferedReader stringReader = new BufferedReader(
                clob.getCharacterStream());
        String singleLine = null;
        StringBuffer strBuff = new StringBuffer();
        while ((singleLine = stringReader.readLine()) != null) {
            strBuff.append(singleLine);
        }
        return strBuff.toString();
    }
}

Related Tutorials