Java SQL ResultSet Clob Read getOracleClob(ResultSet p_rset, int p_col)

Here you can find the source of getOracleClob(ResultSet p_rset, int p_col)

Description

static method for fetching an Oracle CLOB value

License

Open Source License

Parameter

Parameter Description
p_rset ResultSet object on which to perform get
p_col int representing the column position in the ResultSet

Return

String containing the value at p_col, otherwise NULL

Declaration

public static final String getOracleClob(ResultSet p_rset, int p_col) 

Method Source Code

//package com.java2s;
/**/*w w w  .  j  a  v a2s  . c om*/
 * 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:
 */

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

  1. getClobAsString(ResultSet rs, String name, String ifnull)
  2. getCLOBContent(ResultSet rs, int clobidx)
  3. readClobUTF16BinaryStream(ResultSet rs, String fieldName)