static method for fetching an Oracle CLOB value - Java java.sql

Java examples for java.sql:Clob

Description

static method for fetching an Oracle CLOB value

Demo Code

/**/*from w w  w  .j  a v  a2s .co  m*/
 * Database functionality abstraction utilities.
 *
 * Supported drivers:
 * - Oracle
 * - PostgreSQL
 * - MySQL (incomplete)
 * - hsql DB (incomplete)
 * - DB2 (incomplete)
 *
 * Copyright (c) 2001-2004 Marc Lavergne. All rights reserved.
 *
 * The following products are free software; Licensee can redistribute and/or 
 * modify them under the terms of   the GNU Lesser General Public License
 * (http://www.gnu.org/copyleft/lesser.html) as published by the Free Software 
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-   1307  USA; 
 * either version 2.1 of the   license, or any later version:
 */
//package com.java2s;
import java.sql.*;
import java.util.logging.Logger;

import java.io.Reader;
import java.io.IOException;

public class Main {
    /**
     * static method for fetching an Oracle CLOB value
     * @param p_rset ResultSet object on which to perform get
     * @param p_col int representing the column position in the ResultSet
     * @return String containing the value at p_col, otherwise NULL
     */
    public static final String getOracleClob(ResultSet p_rset, int p_col) {
        //    byte[] v_data = null;

        if (p_rset == null) {
            Logger.getAnonymousLogger().severe("NULL ResultSet detected"); //$NON-NLS-1$
            return ""; //$NON-NLS-1$
        }

        try {
            Clob v_clob = p_rset.getClob(p_col);
            if (v_clob != null) {
                Reader v_stream;
                char[] v_buf = new char[(int) v_clob.length()];
                v_stream = v_clob.getCharacterStream();
                v_stream.read(v_buf);
                v_stream.close();
                return new String(v_buf);
            }
            return ""; //$NON-NLS-1$
        } catch (IOException e_io) {
            Logger.getAnonymousLogger().severe(e_io.toString());
            return null;
        } catch (SQLException e_sql) {
            Logger.getAnonymousLogger().severe(e_sql.toString());
            return null;
        }
    }
}

Related Tutorials