Java SQL ResultSet Read getCharacterStream(ResultSet resultSet, String columnName)

Here you can find the source of getCharacterStream(ResultSet resultSet, String columnName)

Description

Returns a string value using a given SQL result set and column name.

License

Open Source License

Parameter

Parameter Description
resultSet - Result set.
columnName - Column name.

Return

String - Column value.

Declaration

public static String getCharacterStream(ResultSet resultSet, String columnName)
        throws SQLException, IOException 

Method Source Code


//package com.java2s;
/*/*  w ww  .  j av a2 s .c  o m*/
 * Copyright (C) 2015 Bryan W. Snipes
 * 
 * This file is part of the JDistil web application framework.
 * 
 * JDistil is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * JDistil is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with JDistil.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.io.BufferedReader;

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

import java.sql.ResultSet;
import java.sql.SQLException;

public class Main {
    /**
      Returns a string value using a given SQL result set and column name.
      @param resultSet - Result set.
      @param columnName - Column name.
      @return String - Column value.
    */
    public static String getCharacterStream(ResultSet resultSet, String columnName)
            throws SQLException, IOException {

        // Initialize return value
        String value = null;

        if (resultSet != null && columnName != null) {

            // Retrieve column value as reader
            Reader reader = resultSet.getCharacterStream(columnName);

            if (reader != null) {

                // Create buffer to store data
                StringBuffer buffer = new StringBuffer();

                // Create buffered reader
                BufferedReader bufferedReader = new BufferedReader(reader);

                // Read first line
                String line = bufferedReader.readLine();

                // Continue processing until all lines are read
                while (line != null) {

                    // Append line to buffer
                    buffer.append(line);

                    // Read next line
                    line = bufferedReader.readLine();
                }

                // Set value
                value = buffer.toString();
            }
        }

        return value;
    }
}

Related

  1. getBestRowId(String schema, String tableName, int scope, String nullable, ResultSet[] rs)
  2. getBigInteger(ResultSet resultSet, int columnIndex)
  3. getBigIntegerFromResultSet(ResultSet rs, String db_name)
  4. getBigObject(ResultSet set, int columnIndex)
  5. getCalendar(ResultSet resultSet, String columnName)
  6. getChunkDelimiters(ResultSet rs, int tsColumnIndex, int chunkSize)
  7. getClassName(ResultSetMetaData meta, int index)
  8. getCountFromResultSet(ResultSet rs)
  9. getData(final ResultSet rs)