Java SQL Blob toByteArray(Blob blob)

Here you can find the source of toByteArray(Blob blob)

Description

to Byte Array

License

LGPL

Declaration

private static byte[] toByteArray(Blob blob) 

Method Source Code

//package com.java2s;
/*//  www  .  j  a  va  2  s  . com
 * Hibernate, Relational Persistence for Idiomatic Java
 *
 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
 * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
 */

import java.sql.Blob;

import java.sql.SQLException;

public class Main {
    private static byte[] toByteArray(Blob blob) {
        try {
            return blob.getBytes(1, (int) blob.length());
        } catch (SQLException e) {
            throw new RuntimeException(
                    "Error on transforming blob into array.", e);
        }
    }
}

Related

  1. isBlob(Object object)
  2. readBlob(Blob blob)
  3. readBytes(Blob blob, byte[] defaultValue)
  4. safeFree(Blob blob)
  5. safeFree(Blob blob)
  6. writeStringToBlob(String value, PreparedStatement preparedStatement, int index)
  7. writeToBlob(int index, PreparedStatement ps, byte[] data)