Java SQL ResultSet Blob Read readFromBlob(ResultSet rs, String column)

Here you can find the source of readFromBlob(ResultSet rs, String column)

Description

read From Blob

License

Open Source License

Declaration

public static byte[] readFromBlob(ResultSet rs, String column) throws SQLException 

Method Source Code

//package com.java2s;
/*//from  ww w  .j  a va  2s.c  o  m
 * Copyright (C) 2010 Francisco Jos? Morero Peyrona. All Rights Reserved.
 *
 * This file is part of Tapas project: http://code.google.com/p/tapas-tpv/
 *
 * GNU Classpath is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the free
 * Software Foundation; either version 3, or (at your option) any later version.
 *
 * Tapas 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * Tapas; see the file COPYING.  If not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

import java.sql.Blob;

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

public class Main {
    public static byte[] readFromBlob(ResultSet rs, String column) throws SQLException {
        byte[] ret = null;
        Blob blob = rs.getBlob(column);

        if (blob != null) {
            long length = blob.length();

            if (length == 0) // Cuando (length == 0) => returns byte[0] en lugar de null
            {
                ret = new byte[0];
            } else {
                ret = blob.getBytes(1, (int) length);
            }

            blob.free();
        }

        return ret;
    }
}

Related

  1. getBlobBytes(ResultSet rs, int iColumn)
  2. getBlobValue(ResultSet result, String strField)
  3. readBlob(ResultSet rs, int index)
  4. readBlobUTF16BinaryStream(ResultSet rs, String fieldName)
  5. readBlobUTF16BinaryStream(ResultSet rs, String fieldName)